Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/j-sephb-lt-n/multi-script-python-logging
A simple example showing how python modules share logging config
https://github.com/j-sephb-lt-n/multi-script-python-logging
logging python
Last synced: about 22 hours ago
JSON representation
A simple example showing how python modules share logging config
- Host: GitHub
- URL: https://github.com/j-sephb-lt-n/multi-script-python-logging
- Owner: J-sephB-lt-n
- License: gpl-3.0
- Created: 2024-01-05T14:16:38.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-01-05T14:36:03.000Z (10 months ago)
- Last Synced: 2024-04-17T22:57:31.059Z (7 months ago)
- Topics: logging, python
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# multi-script-python-logging
This repo contains a simple example illustrating how imported modules (module1.py and module.py) inherit their logging format from the script which imported them (main.py).
```python
# module1.py #
import logging
logger = logging.getLogger(__name__)
def explain():
logger.info("this is a log message from module1.py")# module2.py #
import logging
logger = logging.getLogger(__name__)
def explain():
logger.info("this is a log message from module2.py")# main.py #
import logging
import module1
import module2logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)if __name__=="__main__":
logger.info("this is a log message from main.py")
module1.explain()
module2.explain()
``````bash
~$ python main.py
2024-01-05 16:32:09,132 - __main__ - INFO - this is a log message from main.py
2024-01-05 16:32:09,132 - module1 - INFO - this is a log message from module1.py
2024-01-05 16:32:09,132 - module2 - INFO - this is a log message from module2.py
```