Skip to content

kaptive.log

This module contains functions for logging messages to stderr.

Copyright 2023 Tom Stanton (tomdstanton@gmail.com) https://github.com/klebgenomics/Kaptive

This file is part of Kaptive. Kaptive is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Kaptive is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Kaptive. If not, see https://www.gnu.org/licenses/.

log(message='', verbose=True, rjust=20, stack_depth=1)

Simple function for logging messages to stderr. Only runs if verbose == True. Stack depth can be increased if the parent function name needs to be exposed.

Source code in kaptive/log.py
36
37
38
39
40
41
42
def log(message: str = '', verbose: bool = True, rjust: int = 20, stack_depth: int = 1):
    """
    Simple function for logging messages to stderr. Only runs if verbose == True.
    Stack depth can be increased if the parent function name needs to be exposed.
    """
    if verbose:  # Only build log if verbosity is requested; simple way of controlling log
        sys.stderr.write(f"{datetime.now():%Y-%m-%d %H:%M:%S} {stack()[stack_depth].function:>{rjust}}] {message}\n")