Skip to content

Beginner project to configurably color log messages, utilizing the standard library's logging module.

License

Notifications You must be signed in to change notification settings

ncgl-git/suffuse-log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

suffuse_log

GitHub license Maintenance PRs Welcome made-with-python PyPI download week

Screenshot 2021-07-23 113324

Overview

suffuse_log is a python library that specializes in ansi-formatting of log messages. It targets local scripts that want to output colored logs to a command line terminal.

However, If you have CLI's that you want to make more engaging, pretty, or additionally communicate their meaning with color, then this is the library for you.

Install

pip install suffuse_log

Getting Started

from suffuse_log import suffuse_formatter

logger = suffuse_formatter.defaultConfig(log_level_no=10)

x.info('this is my message')

Features

  • Individually color logging attributes!
  • Conditionally color multiple logging attributes based on glob patterns or user-defined callables
  • Defaults to the popular colorama ansi library
  • Allows users to supply their own ansi-style dictionary

Details

This line in the defaultConfig function:

    format_ansi["%(levelname)s"] = AnsiConfig(
        {
            "DEBUG": ("green_fore", "dim_style"),
            "INFO": ("blue_fore",),
            "WARNING": ("yellow_fore",),
            "ERROR": (bright, "red_fore"),
            "CRITICAL": (bright, "red_fore"),
        },
        ("levelname", "message", "name", "module", "lineno"),
    )

tells us how to color the listed attributes when the levelname is one of the dictionary keys.

Additionally, this line:

    format_ansi["%(message)s"] = AnsiConfig(
        {
            "*error*": (bright,),
            "*important*": (bright,),
            "*critical*": (bright,),
            "*warn*": (bright,),
            "*alert*": (bright,),
        },
        case_sensitive_glob=False,
    )

says that when the listed glob patterns are matched, then additionally make the message bright.

Together this functionality gives us some powerful abilities in how we conditionally color and style our messages.

About

Beginner project to configurably color log messages, utilizing the standard library's logging module.

Topics

Resources

License

Stars

Watchers

Forks