ahriman.core.log package

Submodules

ahriman.core.log.http_log_handler module

class HttpLogHandler(repository_id: RepositoryId, configuration: Configuration, *, report: bool, suppress_errors: bool)

Bases: Handler

handler for the http logging. Because default logging.handlers.HTTPHandler does not support cookies authorization, we have to implement own handler which overrides the logging.handlers.HTTPHandler.emit() method

reporter

build status reporter instance

Type:

Client

suppress_errors

suppress logging errors (e.g. if no web server available)

Type:

bool

Parameters:
  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

  • suppress_errors (bool) – suppress logging errors (e.g. if no web server available)

classmethod load(repository_id: RepositoryId, configuration: Configuration, *, report: bool) Self

install logger. This function creates handler instance and adds it to the handler list in case if no other http handler found

Parameters:
  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

Returns:

logger instance with loaded settings

Return type:

Self

emit(record: LogRecord) None

emit log records using reporter client

Parameters:

record (logging.LogRecord) – log record to log

ahriman.core.log.journal_handler module

JournalHandler

alias of _JournalHandler

ahriman.core.log.lazy_logging module

class LazyLogging

Bases: object

wrapper for the logger library inspired by scala lazy logging module

in_context(name: str, value: Any) Iterator[None]

execute function while setting log context. The context will be reset after the execution

Parameters:
  • name (str) – attribute name to set on log records

  • value (Any) – current value of the context variable

in_package_context(package_base: str, version: str | None) Iterator[None]

execute function while setting package context

Parameters:
  • package_base (str) – package base to set context in

  • version (str | None) – package version if available

Examples

This function is designed to be called as context manager with package_base argument, e.g.:

>>> with self.in_package_context(package.base, package.version):
>>>     build_package(package)
property logger: Logger

get class logger instance

Returns:

class logger instance

Return type:

logging.Logger

property logger_name: str

extract logger name for the class

Returns:

logger name as combination of module name and class name

Return type:

str

ahriman.core.log.log_context module

class LogContext

Bases: object

logging context manager which provides context variables injection into log records

classmethod get(name: str) T | None

get context variable if available

Parameters:

name (str) – name of the context variable

Returns:

context variable if available and None otherwise

Return type:

T | None

classmethod log_record_factory(*args: Any, **kwargs: Any) LogRecord

log record factory which injects all registered context variables into log records

Parameters:
  • *args (Any) – positional arguments for the log factory

  • **kwargs (Any) – keyword arguments for the log factory

Returns:

log record with context variables set as attributes

Return type:

logging.LogRecord

classmethod register(name: str) ContextVar

(re)create context variable for log records

Parameters:

name (str) – name of the context variable

Returns:

created context variable

Return type:

contextvars.ContextVar[T]

classmethod reset(name: str, token: Token) None

reset context variable to its previous value

Parameters:
  • name (str) – attribute name to reset on log records

  • token (contextvars.Token[T]) – previously registered token

classmethod set(name: str, value: T) Token

set context variable for log records. This value will be automatically emitted with each log record

Parameters:
  • name (str) – attribute name to set on log records

  • value (T) – current value of the context variable

Returns:

token created with this value

Return type:

contextvars.Token[T]

ahriman.core.log.log_loader module

class LogLoader

Bases: object

simple static method class which setups application loggers

DEFAULT_LOG_FORMAT

(class attribute) default log format (in case of fallback)

Type:

str

DEFAULT_LOG_LEVEL

(class attribute) default log level (in case of fallback)

Type:

int

DEFAULT_LOG_STYLE

(class attribute) default log style (in case of fallback)

Type:

str

DEFAULT_SYSLOG_DEVICE

(class attribute) default path to syslog device

Type:

Path

static handler(selected: LogHandler | None) LogHandler

try to guess default log handler. In case if selected is set, it will return specified value with appended _handler suffix. Otherwise, it will try to import journald handler and returns ahriman.models.log_handler.LogHandler.Journald if library is available. Otherwise, it will check if there is /dev/log device and returns ahriman.models.log_handler.LogHandler.Syslog in this case. And, finally, it will fall back to ahriman.models.log_handler.LogHandler.Console if none were found

Parameters:

selected (LogHandler | None) – user specified handler if any

Returns:

selected log handler

Return type:

LogHandler

static load(repository_id: RepositoryId, configuration: Configuration, handler: LogHandler, *, quiet: bool, report: bool) None

setup logging settings from configuration

Parameters:
  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • handler (LogHandler) – selected default log handler, which will be used if no handlers were set

  • quiet (bool) – force disable any log messages

  • report (bool) – force enable or disable reporting

static register_context() None

register logging context

Module contents