My personal package for colored logs. Highly customizable.
Project description
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 loggerlvl
: 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 configurationsimple
: simple logger that works like print() but with colorsprofesionall
: 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)
Built Distribution
Close
Hashes for easy_logs-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbc64b89b15d22a241da3832c97429638982db5366415af8f045c92d5cd65f40 |
|
MD5 | 947edd146a4b75357926936367750c9f |
|
BLAKE2b-256 | be0c4ab62294db90c1b247849aab94b3967b38c5c9e909c6cbead1dca4de98b7 |