koi_net.infra.log_system

Logging system for all components, lifecycle, and assembly processes.

Classes

LogSystem([use_file_handler, ...])

Configures and initializes the logging system.

PartitionedFileHandler([log_file_name, ...])

Writes logs to partitioned file supporting multiple nodes running simultaneously in the same execution environment.

class koi_net.infra.log_system.LogSystem(use_file_handler=True, use_console_handler=True, file_handler_log_level=10, console_handler_log_level=10)[source]

Bases: object

Configures and initializes the logging system.

Uses two log handlers by default. One prints to the console, the other produces NDJSON log files, which can be viewed using LNAV.

Parameters:
  • use_file_handler (bool)

  • use_console_handler (bool)

  • file_handler_log_level (int)

  • console_handler_log_level (int)

configure()[source]
configure_console_handler()[source]
console_handler_log_level: int
static delete_file_handler(log_dir, wipe_logs=False)[source]
Parameters:
  • log_dir (str)

  • wipe_logs (bool)

file_handler_log_level: int
use_console_handler: bool
use_file_handler: bool
class koi_net.infra.log_system.PartitionedFileHandler(log_file_name='log.ndjson', max_log_file_size=10485760, num_log_file_backups=5, log_file_encoding='utf-8')[source]

Bases: Handler

Writes logs to partitioned file supporting multiple nodes running simultaneously in the same execution environment.

Intended to be used with LoggingContext component, which binds a node’s root_dir to the log_dir context var. As a result, every node in an execution environment should send logs to the log file in their own root directory. Oftentimes logs produced by third party libraries fall through the cracks and are written to dropped_logs.txt instead as a fallback.

This system is overly complicated and is worth refactoring.

Parameters:
  • log_file_name (str)

  • max_log_file_size (int)

  • num_log_file_backups (int)

  • log_file_encoding (str)

del_handler(log_dir, wipe_logs=False)[source]
Parameters:
  • log_dir (str)

  • wipe_logs (bool)

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

Parameters:

record (LogRecord)

get_handler(log_dir)[source]
Parameters:

log_dir (str)

handlers: dict[str, RotatingFileHandler]