Skip to main content

My personal package for colored logs. Highly customizable.

Project description

example workflow PyPI version pre-commit

easy_logging

this repo contains some of my scripts and tools, that i could not find anywhere else.

installation:

pip install easy_logging

description

This module provides a convenient way to create loggers with colored logs and filtering for IPython/Jupyter Notebook cells.

The main function get_logger can be used to obtain a logger with various configurations, including colored logs, saving logs to a file, and specifying log formatting. Additionally, it supports predefined configurations that simplify logger setup.

usage

get_logger

returns highly configurable logger object.

  • Every level has its own color. (If it is printed to terminal)
  • Problems with logging messages from ipynb cells are resolved.
  • Includes validation for file name and path.
  • Has disable_existing_loggers param to disable all other loggers.

params:

  • logger_name - name of the logger
  • lvl: logging level. Default is 10 (DEBUG).
  • file_name: file that logs will be saved to. If None, logs will not be saved to file.
  • format: logging format.
  • datefmt: date format for logging formatter. Define only if (asctime) in format Default is "%H:%M:%S".
  • disable_existing_loggers: if True, disable existing loggers.
  • predefined: Choose predefined configuration. Will override all other arguments

predefined_configuration:

  • default: default configuration
  • simple: simple logger that works like print() but with colors
  • profesionall: saves logs to file, displays time, filename line number and lvl

Example 1:

from easy_logging.utils import get_logger
logger = get_logger(lvl = 10)
logger.debug("debug")
logger.info("info")
logger.warning("warning")
logger.error("error")
logger.critical("critical")

output:

example 2:

from easy_logging.utils import get_logger
logger = get_logger(
    datefmt="%Y-%m-%d %H:%M:%S",
    format="%(asctime)s %(levelname)s %(funcName)s %(message)s",
    disable_existing_loggers=True,
    logger_name="test2",
    file_name = None,
    lvl="INFO",
)


def example_func():
    logger.debug("debug")
    logger.info("info")
    logger.warning("warning")
    logger.error("error")
    logger.critical("critical")
example_func()

output:

example 3:

from easy_logging import get_logger
logger = get_logger(predefined="simple")
logger.debug("debug")
logger.info("info")
logger.warning("warning")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easy_logs-1.0.0.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

easy_logs-1.0.0-py3-none-any.whl (5.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page