Table of Contents
- Then in the root __init__.py add following lines
from . import logger
logger.initialize_project_logger(
name=__name__,
path_dir_where_to_store_logs="",
is_stdout_debug=False,
is_to_propagate_to_root_logger=False,
)
- And after imports in every python module add the following lines
import logging
LOGGER = logging.getLogger(__name__)
Now you have perfectly set up logger for your library or package
LOGGER.info("hihi")
In the default set up shown above all log messages are sent to stdout and stderr streams.
- LOGGER.debug("hi") -> Not printed
- LOGGER.info("hi") -> "hi"
- LOGGER.warning("hi") -> [WARNING]: hi
- LOGGER.error("hi") -> Not printed
- LOGGER.critical("hi") -> Not printed
- LOGGER.error("hi") -> [Long description of where and when error occured]: hi
- LOGGER.critical("hi") -> [Long description of where and when critical error occured]: hi
If argument is given with non zero value then in the asked directory will be created folder Logs with 2 files:
- Logs/debug.log - To contain all messages starting from debug level
- Logs/errors.log - To contain all errors and critical messages
For both these files every line of them contain one sent message in a dict format so you can easily parse it
If set to True then debug messages also sent to stdout stream in the format: [DEBUG]: msg
Can be useful while you debugging your library or application
If set to True then LOGGER messages will propagate to parent loggers until root logger
Can be used if you expect that user will want to read logs in user own format.
- Email: [email protected]
- vk.com
This project is licensed under the MIT License.