ez_logger package¶
Submodules¶
ez_logger.base_logger module¶
-
class
ez_logger.base_logger.
BaseLogger
(name, log_level)¶ Bases:
object
BaseLogger is the parent class, that encapsulates the common functionality for different kinds of loggers.
ConsoleLogger and FileLogger descend from BaseLogger
Don’t create BaseLogger objects. It is an abstract class. Use ConsoleLogger or FileLogger or TenantLogger.
-
critical
(message)¶ Writes error messages, these messages will be written regardless of the log_level (it could be set to debug, info, warning, error or critical).
-
debug
(message)¶ Writes debug messages, these messages will only be written if log_level is set to debug.
-
error
(message)¶ Writes error messages, these messages will only be written if log_level is set to debug, info, warning or error.
-
info
(message)¶ Writes info messages, these messages will only be written if log_level is set to debug or info.
-
warning
(message)¶ Writes warning messages, these messages will only be written if log_level is set to debug, info or warning.
-
ez_logger.console_logger module¶
-
class
ez_logger.console_logger.
ConsoleLogger
(name=None, log_level='info')¶ Bases:
ez_logger.base_logger.BaseLogger
ConsoleLogger provides a logger that could be used for simple log messages to console. It uses colorlog formatter to color code log messages for different log levels.
- name : string, optional
- Name of the logger.
- log_level : string, optional
- log_level Default value is info. Other allowed values are debug, warning, error or critical
>>> logger = ConsoleLogger() >>> logger.info(message='process started')
ez_logger.file_logger module¶
-
class
ez_logger.file_logger.
FileLogger
(console_logging=True, log_level='info', name=None, log_file=None, log_dir=None)¶ Bases:
ez_logger.base_logger.BaseLogger
FileLogger provides a logger that could be used for batch processing applications. It uses colorlog formatter to color code log messages for different log levels.
- name : string, optional
- Name of the logger.
- log_level : string, optional
- log_level Default value is info. Other allowed values are debug, warning, error or critical
- console_logging : bool, optional
- Should log messages be shown on the console? Default is True
- log_file : string, optional
- If not specified, then it will use a file_name { name }.log. If name is none then the log file will be app.log
- log_dir : string, optional
- The directory where the log_file is created. If not specified, then log_file will be created in the current directory. If directory does not exist, or the user does not have write permission, then log_file will be created in current directory.
>>> logger = FileLogger(log_file='test.log', log_dir='/tmp') >>> logger.info(message='process started')
ez_logger.tenant_logger module¶
-
class
ez_logger.tenant_logger.
TenantLogger
(console_logging=True, log_level='info', name=None, log_file=None, log_dir=None)¶ Bases:
ez_logger.file_logger.FileLogger
TenantLogger is a file logger that can be used when the application uses a single log file for processing multiple clients. It descends from FileFormatter and overrides the formatter, log, warn, debug, critical methods
- name : string, optional
- Name of the logger.
- log_level : string, optional
- log_level Default value is info. Other allowed values are debug, warning, error or critical
- console_logging : bool, optional
- Should log messages be shown on the console? Default is True
- log_file : string, optional
- If not specified, then it will use a file_name { name }.log. If name is none then the log file will be app.log
- log_dir : string, optional
- The directory where the log_file is created. If not specified, then log_file will be created in the current directory. If directory does not exist, or the user does not have write permission, then log_file will be created in current directory.
>>> logger = TenantLogger(log_file='multi-tenant.log', log_dir='/tmp') >>> logger.info(message='Process started', tenant='tenant1')
-
critical
(message, tenant=None)¶ Writes error messages, these messages will be written regardless of the log_level (it could be set to debug, info, warning, error or critical). Formatter will use the tenant name in the log record.
-
debug
(message, tenant=None)¶ Writes debug messages, these messages will only be written if log_level is set to debug. Formatter will use the tenant name in the log record.
-
error
(message, tenant=None)¶ Writes error messages, these messages will only be written if log_level is set to debug, info, warning or error. Formatter will use the tenant name in the log record.
-
info
(message, tenant=None)¶ Writes info messages, these messages will only be written if log_level is set to debug or info. Formatter will use the tenant name in the log record.
-
warning
(message, tenant=None)¶ Writes warning messages, these messages will only be written if log_level is set to debug, info or warning. Formatter will use the tenant name in the log record.