Skip to content

logging_utils

The logging utils are made available to easily log events and make them available on seq.

get_logger(team='physical_operations', application_name=None, job_id=None)

Returns a seq tailored logger instance. This logger is configured to serialize log records into JSON format and includes additional metadata such as environment and team information. The logger is set up to write to standard error (stderr) and uses a custom serialization function to format log messages which seq can consume.

Parameters:

Name Type Description Default
team str

The team name to include in the log output. Defaults to "physical_operations".

'physical_operations'
application_name str

The application name to include in the log output. Optional and defaults to None.

None
job_id str

The job id to include in the log output. Optional and defaults to None.

None

Returns:

Name Type Description
logger Logger

A loguru logger instance configured for JSON serialization.

Example
from physical_operations_utils.logging_utils import get_logger

logger = get_logger(team='myteam')
logger.info("This is an info message.")
logger.error("This is an error message.")
logger.exception("An exception occurred.")
logger.success("This is a success message.")
logger.critical("This is a critical message.")
logger.debug("This is a debug message.")
logger.warning("This is a warning message.")
Source code in physical_operations_utils/logging_utils.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def get_logger(
    team: str = "physical_operations",
    application_name: Optional[str] = None,
    job_id: Optional[str] = None,
) -> Logger:
    """Returns a seq tailored logger instance.
    This logger is configured to serialize log records into JSON format and
    includes additional metadata such as environment and team information.
    The logger is set up to write to standard error (stderr) and uses a custom
    serialization function to format log messages which seq can consume.

    Args:
        team (str): The team name to include in the log output. Defaults to "physical_operations".
        application_name (str): The application name to include in the log output. Optional and defaults to None.
        job_id (str): The job id to include in the log output. Optional and defaults to None.

    Returns:
        logger: A loguru logger instance configured for JSON serialization.

    Example:
        ```python
        from physical_operations_utils.logging_utils import get_logger

        logger = get_logger(team='myteam')
        logger.info("This is an info message.")
        logger.error("This is an error message.")
        logger.exception("An exception occurred.")
        logger.success("This is a success message.")
        logger.critical("This is a critical message.")
        logger.debug("This is a debug message.")
        logger.warning("This is a warning message.")
        ```
    """
    return logger.patch(
        make_patching(team=team, application_name=application_name, job_id=job_id)
    )