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:
- format_message(message: str, args_str: list[str], level_str: str, time_str: str, stack: FrameInfo) str #
Formats given message with formatter attribute
- 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
exception (Exception | None) – Exception (if haven) to log
stack (inspect.FrameInfo) – FrameInfo about caller of the log function
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
- class ezlog.handlers.FileHandler(path: PathLike[str] | str, **kwargs: Any)#
Bases:
LoggerHandler
Handle file for logging
- Variables:
path – Path to the file
- 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
:
- 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
:
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:
- format_message(message: str, args_str: list[str], level_str: str, time_str: str, stack: FrameInfo) str #
Formats given message with formatter attribute
- 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
exception (Exception | None) – Exception (if haven) to log
stack (inspect.FrameInfo) – FrameInfo about caller of the log function
ezlog.exceptions#
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