Skip to content

logging

DGM Logging

Custom logger module for coloured logging to console and file logging.

Usage

Logging

To use * import from dgmlogging.logger import Logger * initialize with Logger.init().

You can set the log level upon initialization or using Logger.set_level(30) or Logger.set_level(logging.WARNING)

Log levels are:

10 logging.DEBUG
15 (custom dgm message logging)
20 logging.INFO
30 logging.WARNING
40 logging.ERROR
50 logging.CRITICAL

Logger

Generic Logger class for logging to file and console in color.

Logging levels are

10 DEBUG 15 DGM 20 INFO 30 WARNING 40 ERROR 50 CRITICAL

get_level() staticmethod

Retrieve the current logging level.

Returns:

Type Description
str

The current logging level.

init(level=logging.INFO, to_file=False, style=0) staticmethod

Initialize the logger with optional parameters level and to_file.

Parameters:

Name Type Description Default
level LEVEL

Logging level. Defaults to INFO.

INFO
to_file bool

Write logs to file debug. Defaults to False.

False
style int

Output message styling. Defaults to 0.

0

set_level(level) staticmethod

Set the logging level.

Parameters:

Name Type Description Default
level LEVEL

Set logging level to this.

required

set_style(style) staticmethod

Set message style.

Parameters:

Name Type Description Default
style int

Log message style.

required

timer(fn)

Time functions with decorator.