Skip to content

Adapter logging

getLogger(name)

A convenience function to get a logger with a specific name.

Parameters:

Name Type Description Default
name str

The name of the logger.

required

Returns:

Type Description
Logger

logging.Logger: The requested logger.

Source code in lib/python/src/aria/ops/adapter_logging.py
def getLogger(name: str) -> logging.Logger:
    """
    A convenience function to get a logger with a specific name.

    Args:
        name (str): The name of the logger.

    Returns:
        logging.Logger: The requested logger.
    """
    return logging.getLogger(name)

rotate()

Rotates the current adapter logs to their backups (e.g., adapter.log to adapter.log.1) and starts logging to the new adapter.log file.

Source code in lib/python/src/aria/ops/adapter_logging.py
def rotate() -> None:
    """
    Rotates the current adapter logs to their backups (e.g., `adapter.log` to
    `adapter.log.1`) and starts logging to the new adapter.log file.
    """
    if log_handler:
        log_handler.doRollover()

setup_logging(filename, file_count=5, max_size=0)

Sets up logging using the given parameters.

Parameters:

Name Type Description Default
filename str

The name of the file to log to.

required
file_count int

The total number of files to retain. Defaults to 5.

5
max_size int

The maximum size in bytes of each file before the file automatically rotates to a new one. Defaults to '0', which will do no automatic rotation. Requires calling the 'rotate()' function manually to ensure logs do not become too large.

0
Source code in lib/python/src/aria/ops/adapter_logging.py
def setup_logging(filename: str, file_count: int = 5, max_size: int = 0) -> None:
    """
    Sets up logging using the given parameters.

    Args:
        filename (str): The name of the file to log to.
        file_count (int, optional): The total number of files to retain. Defaults to 5.
        max_size (int, optional): The maximum size in bytes of each file before the file
                                  automatically rotates to a new one. Defaults to '0', which will
                                  do no automatic rotation. Requires calling the 'rotate()' function
                                  manually to ensure logs do not become too large.
    """
    logdir = os.path.join(os.sep, "var", "log")
    if os.access(logdir, os.W_OK):
        try:
            global log_handler
            log_handler = RotatingFileHandler(
                os.path.join(os.sep, "var", "log", filename),
                maxBytes=max_size,
                backupCount=file_count,
            )
            logging.basicConfig(
                format="%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S",
                level=_get_default_log_level(),
                handlers=[log_handler],
            )
            _set_log_levels()
        except Exception as e:
            logging.basicConfig(level=logging.INFO)
            logging.exception(e)
    else:
        logging.basicConfig(level=logging.INFO)
        logging.exception(
            f"Cannot write to log file '{os.path.join(logdir, filename)}'"
        )