Module rugged.lib.logger

Functions

def get_log_entries(log)
Expand source code
def get_log_entries(log):
    """ Return a dictionary of log entries for a given log. """
    log_files = get_log_files(log)
    return _get_log_entries(log_files)

Return a dictionary of log entries for a given log.

def get_log_files(log)
Expand source code
def get_log_files(log):
    """ Return a list of log files for the given logger. """
    log_files = []
    for handler in log.handlers:
        if hasattr(handler, 'baseFilename'):
            log_files.append(handler.baseFilename)
    return log_files

Return a list of log files for the given logger.

def get_logger()
Expand source code
def get_logger():
    """ Return the existing TUF logging service."""
    return logging.getLogger(RUGGED_LOGGER)

Return the existing TUF logging service.

def get_rugged_logger()
Expand source code
def get_rugged_logger():
    """ Instantiate, configure and return the TUF logging service."""
    return Log(RUGGED_LOGGER).get_logger()

Instantiate, configure and return the TUF logging service.

def log_exception(exception) ‑> None
Expand source code
def log_exception(exception) -> None:
    """ Log an exception's class and message. """
    log = get_logger()
    exception_class = exception.__class__.__name__
    caller = sys._getframe().f_back.f_code.co_name  # pyrefly: ignore[missing-attribute]
    log.error(f"{exception_class} thrown in {caller}: {exception}")

Log an exception's class and message.

def truncate_log(log)
Expand source code
def truncate_log(log):
    """ Delete all entries from logs. """
    truncated_log_files = []
    for logfile in get_log_files(log):
        with open(logfile, 'w') as file:
            file.truncate
        truncated_log_files.append(logfile)
    return truncated_log_files

Delete all entries from logs.

Classes

class Log (name)
Expand source code
class Log:

    def __init__(self, name):
        self.logger = logging.getLogger(name)
        click_log.basic_config(self.logger)
        config = get_config()
        handler = logging.FileHandler(config['log_file'].get())
        formatter = logging.Formatter(config['log_format'].get())
        handler.setFormatter(formatter)
        self.logger.setLevel(logging.INFO)
        self.logger.addHandler(handler)

    def get_logger(self):
        return self.logger

Methods

def get_logger(self)
Expand source code
def get_logger(self):
    return self.logger