Skip to content

This is an additional implementation over the logging module. This module is designed for fast initialization and configuration of readable and structured logging.

License

Notifications You must be signed in to change notification settings

obervinov/logger-package

Repository files navigation

Logger Package

Release CodeQL PR

GitHub release (latest SemVer) GitHub last commit GitHub Release Date GitHub issues GitHub repo size

About this project

This is an additional implementation over the logging module.

This module is designed for fast initialization and configuration of readable and structured logging.

Supported functions

  • Color selection depending on the logging level
  • Structured and formatted message for more informative
  • Loading the logger configuration and format from a environment variables

Installing with Poetry

tee -a pyproject.toml <<EOF
[tool.poetry]
name = myproject"
version = "1.0.0"

[tool.poetry.dependencies]
python = "^3.12"
logger = { git = "https://github.com/obervinov/logger-package.git", tag = "v2.0.0" }

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
EOF

poetry install

Usage example

Environment variables

Name Description Default value
LOGGER_FORMAT A string with the event logging format [%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s
LOGGER_LEVEL Event logging level: DEBUG, INFO, WARNING, ERROR, CRITICAL or NOT SET INFO
LOGGER_DATE_FORMAT Date format in logging event output %d/%b/%Y %H:%M:%S

Examples

Simple

# Import module
from logger import log

# Examples
# error message
log.error(f"this error: {error}")
# warning message
log.warning(f"this warning: {warn}")
# info message
log.info(f"this info: {info}")

With using class

# Import module
from logger import log

# Add logger to class
class myproject:
  def __init__(self):
    self.log = create_logger(__name__, self.__class__.__name__)
    self.log.info("Init my class")

  def warning(self):
    self.log.warning("Warning")

  def error(self):
    self.log.error("Critical error")

  def debug(self):
    self.log.debug("Debug")

mp = myproject()
mp.warning()
mp.error()
mp.debug()

GitHub Actions

Name Version
GitHub Actions Templates v2.0.0

About

This is an additional implementation over the logging module. This module is designed for fast initialization and configuration of readable and structured logging.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Languages