Skip to content

A simple Logger for Python which includes rich formatting for console prints.

License

Notifications You must be signed in to change notification settings

EliasBrohammer/RichLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RichLogger

A simple Logger for Python which includes rich formatting for console prints.

Idea

The idea is to have this logging class to do the heavy lifting to initialize the python logging module and support printing to the console. If logging to a file is not necessary the library can be used in the same way, by simply printing to the console or do nothing.

Usage

To use the RichLogger library, follow these steps:

  1. Install the library using pip:

    pip install rich-logger
  2. Import the library in your Python script:

    from rich_logger import RichLogger
  3. Initialize the logger:

    logger = RichLogger(name="my_logger", level="DEBUG")
  4. Use the logger to log messages:

    logger.debug("This is a debug message")
    logger.info("This is an info message")
    logger.warning("This is a warning message")
    logger.error("This is an error message")
    logger.critical("This is a critical message")

The logger will handle the formatting and output of the messages to the console.

If you want to log only to a file use:

logger = RichLogger(logging_to_file=True, logging_to_console=False)

You can also combine both and have a console and file logging by setting the variables logging_to_file and logging_to_console accordingly.

Tests

Tests run locally via:

coverage run -m unittest discover tests/

Visualized with:

coverage report -m

Resulting in:

Name Stmts Miss Cover Missing
rich_logger__init__.py 0 0 100%
rich_logger\console_logger_highlighter.py 12 0 100%
rich_logger\defaults.py 3 0 100%
rich_logger\rich_logger.py 47 0 100%
rich_logger\utils.py 16 0 100%
tests\test_rich_logger.py 36 0 100%
TOTAL 114 0 100%

Tested python versions:

  • 3.11.11
  • 3.12.8
  • 3.13.1

License

The License is MIT, for further information see License file

About

A simple Logger for Python which includes rich formatting for console prints.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages