zapish_logger package

Submodules

zapish_logger.logger module

The JSON logger

class zapish_logger.logger.LoggingConfig(log_format: str | None = 'json', custom_logging_formatters: Dict[str, str] | None = None)[source]

Bases: object

Class to build a dictionary logging config

Parameters:
  • log_format (Optional[str] = 'json') – Set the default log format

  • custom_logging_formatters (Optional[Dict[str, str]] = None) – Logging formatters example: {‘the_name’: ‘the format’}

Return type:

None

Returns:

Nothing

FILE_SIZE_OPTIONS = {'B': 1, 'G': 1000000000, 'K': 1000, 'M': 1000000}
FORMAT_OPTIONS = {'clean': {'clean': {'format': '[%(asctime)s] %(levelname)s:%(name)s - %(message)s'}}, 'json': {'json': {'format': '{"level": "%(levelname)s", "ts": "%(asctime)s", "caller": "%(name)s", "msg": "%(message)s"}'}}, 'simple': {'simple': {'format': '%(asctime)s: %(name)s - %(levelname)s - %(message)s'}}}
LEVEL_OPTIONS = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL', 'NOTSET')
add_console_handler(log_format: str | None = None) None[source]

Add a console logger

Parameters:

log_format (Optional[str] = None) – To override the instantiated log_format

Return type:

None

Returns:

Nothing it adds a console logger

Raises:

ValueError – If log_format is not a valid format

add_file_handler(path: str, level: str | None = 'INFO', log_format: str | None = None) None[source]

Add a file logger

Parameters:
  • path (String) – The full path to the log file Example: /tmp/some_log.log

  • level (Optional[str] = 'INFO') – To set the logging level

  • log_format (Optional[str] = None) – To override the instantiated log_format

Return type:

None

Returns:

Nothing it adds a file logger

Raises:
  • ValueError – If level is not a valid option

  • ValueError – If log_format is not a valid format

add_rotating_file_handler(path: str, level: str | None = 'INFO', log_format: str | None = None, max_file_size: str | None = '5M', backup_count: int | None = 3) None[source]

Add a rotating file logger

Parameters:
  • path (String) – The full path to the log file Example: /tmp/some_log.log

  • level (Optional[str] = 'INFO') – To set the logging level

  • log_format (Optional[str] = None) – To override the instantiated log_format

  • max_file_size (max_file_size: Optional[str] = '5M') – Maximum file size before rotation

  • backup_count (backup_count: Optional[int] = 3) – The number of backup files to keep

Return type:

None

Returns:

Nothing it adds a file logger

Raises:
  • ValueError – If level is not a valid option

  • ValueError – If log_format is not a valid format

  • ValueError – If max_file_size is not formatted properly

  • TypeError – If backup_count is not an integer

get_config() dict[source]

Get the configuration

Return type:

Dict

Returns:

A logging configuration

zapish_logger.logger.console_logger(name: str, log_format: str | None = 'json') Logger[source]

Function to get a console logger

Parameters:
  • name (String) – The name of the logger

  • log_format (Optional[str] = 'json') – Set the log format

Return type:

logging.Logger

Returns:

The logger

zapish_logger.logger.custom_logger(logging_config: LoggingConfig, name: str) Logger[source]

Function to get a custom logger

Parameters:
  • logging_config (zapish_logger.LoggingConfig) – The logging config

  • name (String) – The name of the logger

Return type:

logging.Logger

Returns:

The logger

zapish_logger.logger.file_and_console_logger(path: str, name: str, level: str | None = 'INFO', log_format: str | None = 'json') Logger[source]

Function to get a rotating file and console logger

Parameters:
  • path (String) – The full path to the log file Example: /tmp/some_log.log

  • level (Optional[str] = 'INFO') – To set the logging level

  • name (String) – The name of the logger

  • log_format (Optional[str] = 'json') – Set the log format

Return type:

logging.Logger

Returns:

The logger

zapish_logger.logger.file_logger(path: str, name: str, level: str | None = 'INFO', log_format: str | None = 'json') Logger[source]

Function to get a file logger

Parameters:
  • path (String) – The full path to the log file Example: /tmp/some_log.log

  • level (Optional[str] = 'INFO') – To set the logging level

  • name (String) – The name of the logger

  • log_format (Optional[str] = 'json') – Set the log format

Return type:

logging.Logger

Returns:

The logger

zapish_logger.logger.process_log_file(data: str) List[Dict[str, str]][source]

Function that converts log entries to dicts and appends to list, also handles non-json log entries the key will be ‘msg’ if the log entry is not json

Parameters:

data (String) – The log data

Return type:

List[Dict[str, str]]

Returns:

Te log data as python objects

zapish_logger.logger.read_log_file(path: str) List[Dict[str, str]][source]

Function that reads log data and converts log entries to dicts and appends to list

Parameters:

path (String) – The full path to the log file Example: /tmp/some_log.log

Return type:

List[Dict[str, str]]

Returns:

Te log data as python objects

zapish_logger.version module

Holds the version information for the package

Module contents

init for zapish_logger