Library#

Note

Modules ezlog.logger, ezlog.loggergroup, ezlog.handlers and ezlog.utils.LogLevel not required to import separately. You can simply import ezlog and use them without ezlog.logger.Logger, ezlog.utils.LogLevel. Other modules required to use as ezlog.exceptions.StringGroupNotFoundException.

ezlog.logger#

Declares Logger - main class of this library.

class ezlog.logger.Logger(name: str, formatter: str | None = None, time_formatter: str | None = None, color_set: dict[str, dict[int | str | type, str]] | None = None, handlers: list[ezlog.handlers.LoggerHandler] | None = None, group: LoggerGroup | str | None = None)#

Bases: object

Class of the Logger

__init__(name: str, formatter: str | None = None, time_formatter: str | None = None, color_set: dict[str, dict[int | str | type, str]] | None = None, handlers: list[ezlog.handlers.LoggerHandler] | None = None, group: LoggerGroup | str | None = None)#
Parameters:
  • name (str) – Name of the logger

  • formatter (str | None) – String formatter of the record

  • time_formatter (str) – String formatter for the time

  • color_set (ColorSetType) – Colors set to use (dict with the colors)

  • handlers (list[LoggerHandler]) – Handlers (List with the LoggerHandler instances). It is using to write records in

  • group (LoggerGroup | str | None) – Group of the handler (Copy all values from)

initialize_group()#

Copy all settings from the group to itself

format_time(time: datetime) str#

Formats a time with time_formatter attribute

Parameters:

time (datetime) – Time to format

Returns:

Formatted time

Return type:

str

format_message(message: str, args_str: list[str], level_str: str, time_str: str, stack: FrameInfo) str#

Formats given message with formatter attribute

Parameters:
  • message (str) – Message to format

  • args_str (list[str]) – Arguments to format message with

  • level_str (str) – Level parameter

  • time_str – Time parameter

  • stack (inspect.FrameInfo) – FrameInfo about caller of the log function

Returns:

Formatter string

Return type:

str

record(message: str, *args: Any, level: int | str = 9999, exception: Exception | None = None, stack: FrameInfo | None = None)#

Records a log to the handlers with formatters usage

Parameters:
  • message (str) – Message to record

  • args (Any) – Arguments to format with message

  • level (int | str) – Log level of the record

  • exception (Exception | None) – Exception (if haven) to log

  • stack (inspect.FrameInfo) – FrameInfo about caller of the log function

debug(message: str, *args, exception: Exception | None = None)#
exception(message: str, *args, exception: Exception | None = None)#
info(message: str, *args, exception: Exception | None = None)#
warning(message: str, *args, exception: Exception | None = None)#
error(message: str, *args, exception: Exception | None = None)#
critical(message: str, *args, exception: Exception | None = None)#
notset(message: str, *args, exception: Exception | None = None)#

ezlog.loggergroup#

class ezlog.loggergroup.LoggerGroup(name: str, parent: LoggerGroup | None = None, formatter: str | None = None, time_formatter: str | None = None, color_set: dict[str, dict[int | str | type, str]] | None = None, handlers: list[ezlog.handlers.LoggerHandler] | None = None, loggers: list['Logger'] | None = None)#

Bases: object

Group of loggers has shared parameters. Is highly recommended to create root logger and after pin all others logger to it

__init__(name: str, parent: LoggerGroup | None = None, formatter: str | None = None, time_formatter: str | None = None, color_set: dict[str, dict[int | str | type, str]] | None = None, handlers: list[ezlog.handlers.LoggerHandler] | None = None, loggers: list['Logger'] | None = None)#
Parameters:
  • name (str) – Name of the group

  • parent (LoggerGroup | None) – Parent of this group

  • formatter (str | None) – Formatter for the logs

  • time_formatter (str | None) – Formatter for the time

  • color_set (ColorSetType | None) – Set of the colors to use

  • handlers (list[LoggerHandler] | None) – Handlers, used to write all logs into

  • loggers (list[Logger] | None) – Loggers to be pinned to this group

Raises:

StringGroupNotFoundException – When string parent group not found

ezlog.handlers#

Defines main ezlog handlers

class ezlog.handlers.LoggerHandler(io: TextIO | None = None, log_level: int | str = 9999, colors: bool = True, exceptions: bool = True)#

Bases: object

Handler for any IO

__init__(io: TextIO | None = None, log_level: int | str = 9999, colors: bool = True, exceptions: bool = True)#
Parameters:
  • io (TextIO) – TextIO to handle

  • log_level (LogLevel | str) – Level of logging (by default is LogLevel.NOTSET)

  • colors (bool) – Enable colors for the handler

  • exceptions (bool) – Enable exception handling for this handler

write(text: str)#

Writes given text to the IO if it doesn’t equal to None

Parameters:

text (str) – Text to write into IO

class ezlog.handlers.FileHandler(path: PathLike[str] | str, **kwargs: Any)#

Bases: LoggerHandler

Handle file for logging

Variables:

path – Path to the file

__init__(path: PathLike[str] | str, **kwargs: Any)#
Parameters:
  • path (PathLike[str] | str) – Path to the file

  • kwargs (Any) – Key=value parameters for the LoggerHandler

Parameters from the LoggerHandler:

Parameters:
  • io (TextIO) – TextIO to handle

  • log_level (LogLevelType) – Level of logging (by default is LogLevel.NOTSET)

  • colors (bool) – Enable colors for the handler

  • exceptions (bool) – Enable exception handling for this handler

class ezlog.handlers.StdoutHandler(**kwargs: Any)#

Bases: LoggerHandler

Handle stdout output (console output)

__init__(**kwargs: Any)#
Parameters:

kwargs (Any) – Key=value parameters for the LoggerHandler

Parameters from the LoggerHandler:

Parameters:
  • io (TextIO) – TextIO to handle

  • log_level (LogLevelType) – Level of logging (by default is LogLevel.NOTSET)

  • colors (bool) – Enable colors for the handler

  • exceptions (bool) – Enable exception handling for this handler

class ezlog.handlers.StderrHandler(**kwargs: Any)#

Bases: LoggerHandler

Handle stderr output (console error output)

__init__(**kwargs: Any)#
Parameters:

kwargs (Any) – Key=value parameters for the LoggerHandler

Parameters from the LoggerHandler:

Parameters:
  • io (TextIO) – TextIO to handle

  • log_level (LogLevelType) – Level of logging (by default is LogLevel.NOTSET)

  • colors (bool) – Enable colors for the handler

  • exceptions (bool) – Enable exception handling for this handler

ezlog.utils#

ezlog.logger#

Declares Logger - main class of this library.

class ezlog.logger.Logger(name: str, formatter: str | None = None, time_formatter: str | None = None, color_set: dict[str, dict[int | str | type, str]] | None = None, handlers: list[ezlog.handlers.LoggerHandler] | None = None, group: LoggerGroup | str | None = None)#

Bases: object

Class of the Logger

__init__(name: str, formatter: str | None = None, time_formatter: str | None = None, color_set: dict[str, dict[int | str | type, str]] | None = None, handlers: list[ezlog.handlers.LoggerHandler] | None = None, group: LoggerGroup | str | None = None)#
Parameters:
  • name (str) – Name of the logger

  • formatter (str | None) – String formatter of the record

  • time_formatter (str) – String formatter for the time

  • color_set (ColorSetType) – Colors set to use (dict with the colors)

  • handlers (list[LoggerHandler]) – Handlers (List with the LoggerHandler instances). It is using to write records in

  • group (LoggerGroup | str | None) – Group of the handler (Copy all values from)

initialize_group()#

Copy all settings from the group to itself

format_time(time: datetime) str#

Formats a time with time_formatter attribute

Parameters:

time (datetime) – Time to format

Returns:

Formatted time

Return type:

str

format_message(message: str, args_str: list[str], level_str: str, time_str: str, stack: FrameInfo) str#

Formats given message with formatter attribute

Parameters:
  • message (str) – Message to format

  • args_str (list[str]) – Arguments to format message with

  • level_str (str) – Level parameter

  • time_str – Time parameter

  • stack (inspect.FrameInfo) – FrameInfo about caller of the log function

Returns:

Formatter string

Return type:

str

record(message: str, *args: Any, level: int | str = 9999, exception: Exception | None = None, stack: FrameInfo | None = None)#

Records a log to the handlers with formatters usage

Parameters:
  • message (str) – Message to record

  • args (Any) – Arguments to format with message

  • level (int | str) – Log level of the record

  • exception (Exception | None) – Exception (if haven) to log

  • stack (inspect.FrameInfo) – FrameInfo about caller of the log function

debug(message: str, *args, exception: Exception | None = None)#
exception(message: str, *args, exception: Exception | None = None)#
info(message: str, *args, exception: Exception | None = None)#
warning(message: str, *args, exception: Exception | None = None)#
error(message: str, *args, exception: Exception | None = None)#
critical(message: str, *args, exception: Exception | None = None)#
notset(message: str, *args, exception: Exception | None = None)#

ezlog.exceptions#

exception ezlog.exceptions.StringGroupNotFoundException(unknown_parent: str)#

Bases: Exception

Exception raised when LoggerGroup can’t find given parent

Variables:

unknown_parent – Unknown string group parent

__init__(unknown_parent: str)#
Parameters:

unknown_parent (str) – Unknown string group parent

ezlog.defaults#

Defines default variables, such as a color set

ezlog.defaults.DEFAULT_COLOR_SET#

Default color set

ezlog.defaults.DEFAULT_FORMATTER = '{time} | {level:<18} | {group_name:<18} -> {name:<18} {message} ln:{stack.lineno} fn:{stack.function}'#

Default formatter of the record message

ezlog.defaults.DEFAULT_TIME_FORMATTER = '{year:04d}.{month:02d}.{day:02d} {hour:02d}:{minute:02d}:{second:02d}.{microsecond:04s}'#

Default formatter of the time