Python logging helper.
- Install sharklog:
python -m pip install sharklog
- Use in standalone script:
# standalone.py
from sharklog import logging
logging.init(debug=True)
logging.debug("debug message")
logging.info("info message")
logging.warning("warning message")
logging.error("error message")
- Use in module:
# submodule.py which is placed under package `parent`
from sharklog import logging
logger = logging.getLogger() # the logger name will be `parent.submodule`
logger.debug("debug message")
logger.info("info message")
logger.warning("warning message")
logger.error("error message")
If you already using builtin logging module, you can use sharklog as a drop-in replacement.
Just change into import logging
from sharklog import logging
. Then you can use logging
as usual:
# module_name.py
from sharklog import logging
# these log messages will be prefixed with the logger name `xxxpackage.xxmodule.module_name`
logging.debug("debug message")
logging.info("info message")
logging.warning("warning message")
logging.error("error message")
# parent/__init__.py
from sharklog import logging
logging.getLogger().addHandler(logging.NullHandler())