Code Monkey home page Code Monkey logo

logger-color's Introduction

logger-color

Different logging levels for stram (terminal) and file. Color the log messages. Has additional levels for diagnostics: DIAG_INFO, DIAG_WARNING.

Level Int Color
DEBUG 10 gray
INFO 20 green
WARNING 30 yellow
ERROR 40 red
CRITICAL 50 bold red
DIAG_INFO 21 blue
DIAG_WARNING 31 blue bold

Python >=3.8

Install the package from pypi.org release

pip install logger-color

or install the package from github.com repository

pip install git+https://github.com/vladimirs-git/logger-color

or install the package from github.com release

pip install https://github.com/vladimirs-git/logger-color/archive/refs/tags/0.0.8.tar.gz

start_logging(filename, mode, level, level_file, color, debug) - Start logging with the specified parameters

Parameter Type Default Description
filename str ย  Writes messages to this file. By default, logging only to the terminal
mode str "w" "w" - Writes to file (default), "a" - Appends to file
level str INFO Logging level for the terminal: "DEBUG", "INFO" (default), "WARNING", "ERROR", "CRITICAL", "DIAG_INFO", "DIAG_WARNING"
level_file str level Logging level for the file. By default, the same as level parameter
color bool True True - Prints a colored message to the terminal (default), False - Prints a monochrome message to the terminal
debug bool False True - Sets logging level to DEBUG (rewrites level parameter), works the same as level="DEBUG". False - Gets logging level from level parameter (default)

debug(args, kwargs) - Log a message with severity "DEBUG"

diag_info(msg, args, kwargs) - Log diagnostic message with severity "INFO"

diag_warning(msg, args, kwargs) - Log diagnostic message with severity "WARNING"

info(args, kwargs) - Log a message with severity "INFO"

warning(args, kwargs) - Log a message with severity "WARNING"

error(args, kwargs) - Log a message with severity "ERROR"

warning(args, kwargs) - Log a message with severity "CRITICAL"

Example

import logger_color

logger_color.start_logging(filename="/var/log/test.log", level="debug", level_file="error")
logger_color.debug("debug")
logger_color.info("info")
logger_color.warning("warning")
logger_color.error("error")
logger_color.critical("critical")
logger_color.diag_info("diag_info")
logger_color.diag_warning("diag_warning")
# 2000-12-31 23:59:59.474 DEBUG    messages.debug: debug
# 2000-12-31 23:59:59.474 INFO     messages.info: info
# 2000-12-31 23:59:59.474 WARNING  messages.warning: warning
# 2000-12-31 23:59:59.474 ERROR    messages.error: error
# 2000-12-31 23:59:59.474 CRITICAL messages.critical: critical
# 2000-12-31 23:59:59.474 DIAG_I   messages.<module>: diag_info
# 2000-12-31 23:59:59.474 DIAG_W   messages.<module>: diag_warning

# cat /var/log/test.log
# 2000-12-31 23:59:59 ERROR    error
# 2000-12-31 23:59:59 CRITICAL critical

logger-color's People

Contributors

vladimirs-git avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.