Skip to content

third_party

Define formatters, handlers, and loggers for third-party dependencies.

get_red_logging_console_handler(name='red_logging_console', level='DEBUG', formatter='red_logging', filters=None)

Return an initialized StreamHandlerConfig for the red_logging library.

Parameters:

Name Type Description Default
name str

The name of the handler, which you will reference in a logger config.

'red_logging_console'
level str

The log level for the handler (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL).

'DEBUG'
formatter str

The name of the formatter to use. This formatter must exist in the logging dictConfig, and can be generated with a FormatterConfig.

'red_logging'
filters list[str] | None

Optional list of filter function names to apply to the handler.

None

Returns:

Type Description
StreamHandlerConfig

An initialized StreamHandlerConfig class.

Source code in src/red_logging/config_classes/prefab/third_party/prefab_red_logging/_configs.py
def get_red_logging_console_handler(
    name: str = "red_logging_console",
    level: str = "DEBUG",
    formatter: str = "red_logging",
    filters: list[str] | None = None,
) -> StreamHandlerConfig:
    """Return an initialized StreamHandlerConfig for the red_logging library.

    Params:
        name (str): The name of the handler, which you will reference in a logger config.
        level (str): The log level for the handler (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL).
        formatter (str): The name of the formatter to use. This formatter must exist in the logging dictConfig,
            and can be generated with a FormatterConfig.
        filters (list[str]|None): Optional list of filter function names to apply to the handler.

    Returns:
        (StreamHandlerConfig): An initialized StreamHandlerConfig class.

    """
    try:
        _handler: StreamHandlerConfig = StreamHandlerConfig(
            name=name, level=level.upper(), formatter=formatter, filters=filters
        )

        return _handler

    except Exception as exc:
        msg = Exception(
            f"Unhandled exception getting red_logging StreamHandlerConfig. Details: {exc}"
        )
        log.error(msg)

        raise exc

get_red_logging_formatter(name='red_logging', fmt=red_logging_FMT, datefmt=DATE_FMT_STANDARD)

Return a pre-configured FormatterConfig for the red_logging library.

Parameters:

Name Type Description Default
name str

The name of the formatter, which you will reference in a handler config.

'red_logging'
fmt str

The log message format string.

red_logging_FMT
datefmt str

The format for timestamps in log messages.

DATE_FMT_STANDARD

Returns:

Type Description
FormatterConfig

An initialized FormatterConfig class

Source code in src/red_logging/config_classes/prefab/third_party/prefab_red_logging/_configs.py
def get_red_logging_formatter(
    name: str = "red_logging", fmt: str = red_logging_FMT, datefmt: str = DATE_FMT_STANDARD
) -> FormatterConfig:
    """Return a pre-configured FormatterConfig for the red_logging library.

    Params:
        name (str): The name of the formatter, which you will reference in a handler config.
        fmt (str): The log message format string.
        datefmt (str): The format for timestamps in log messages.

    Returns:
        (FormatterConfig): An initialized FormatterConfig class

    """
    try:
        _formatter: FormatterConfig = get_formatter_config(
            name=name, fmt=fmt, datefmt=datefmt
        )

        return _formatter

    except Exception as exc:
        msg = Exception(
            f"Unhandled exception getting red_logging FormatterConfig. Details: {exc}"
        )
        log.error(msg)

        raise exc

get_red_logging_logger(name='red_logging', handlers=['red_logging_console'], level='WARNING', propagate=False)

Return an initialized LoggerConfig for the red_logging library.

Parameters:

Name Type Description Default
name str

The name of the logger, which you will reference in a logging config dict.

'red_logging'
handlers list[str]

A list of handler names for the logger. These loggers must exist in the dictConfig.

['red_logging_console']
level str

The log level for the handler (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL).

'WARNING'
propagate bool

If False, logs from this logger will not be propagated down/up to the root logger.

False

Returns:

Type Description
LoggerConfig

An initialized LoggerConfig class.

Source code in src/red_logging/config_classes/prefab/third_party/prefab_red_logging/_configs.py
def get_red_logging_logger(
    name: str = "red_logging",
    handlers: list[str] = ["red_logging_console"],
    level: str = "WARNING",
    propagate: bool = False,
) -> LoggerConfig:
    """Return an initialized LoggerConfig for the red_logging library.

    Params:
        name (str): The name of the logger, which you will reference in a logging config dict.
        handlers (list[str]): A list of handler names for the logger. These loggers must exist in the dictConfig.
        level (str): The log level for the handler (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL).
        propagate (bool): If `False`, logs from this logger will not be propagated down/up to the root logger.

    Returns:
        (LoggerConfig): An initialized LoggerConfig class.

    """
    try:
        _logger: LoggerConfig = get_logger_config(
            name=name, handlers=handlers, level=level.upper(), propagate=propagate
        )

        return _logger

    except Exception as exc:
        msg = Exception(
            f"Unhandled exception getting red_logging LoggerConfig. Details: {exc}"
        )
        log.error(msg)

        raise exc