/basic_package_logger

This is a one-file library with only one function get_logger which can be used as a logger set up for new py packages and libraries

Primary LanguagePythonMIT LicenseMIT

The Perfect First LOGGER

This is a one file (logger.py) library with only one function (initialize_project_logger)
which returns a LOGGER that can be used as first logger in many cases
Whenever you are creating a new python library or package
just add the file logger.py from this repo into the root of you project
  1. 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,
)
  1. 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

Both files are rotating when size is bigger than 10 Mb.
At that moment backup file is created by appending the extensions .1 (Logs/debug.log.1)
and main file is cleared and used for next messages

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.

This project is licensed under the MIT License.