Skip to content

litmus_rm.logging

logging.py

Collection of logging functions in a handy inheritable class, to make it easier to edit later in one place

logger(verbose: Union[bool, int] = True, debug: Union[bool, int] = False, warn: Union[bool, int] = 0)

Object class that contains methods for printing to debug, verbose and error streams. Internal behaviour may change in future releases

:param out_stream: Stream to print run and debug messages to [removed as it breaks pickling]
:param err_stream: Stream to print error messages to [removed as it breaks pickling]

Parameters:

Name Type Description Default
verbose Union[bool, int]

Whether to print msg_run statements / lvl of reporting

True
debug Union[bool, int]

Whether to print msg_debug statements / lvl of reporting

False
warn Union[bool, int]

Whether to print msg_debug statements / lvl of warnings

0
Source code in src/litmus_rm/logging.py
def __init__(self, verbose: Union[bool, int] = True,
             debug: Union[bool, int] = False,
             warn: Union[bool, int] = 0):
    """
    # :param out_stream: Stream to print run and debug messages to [removed as it breaks pickling]
    # :param err_stream: Stream to print error messages to  [removed as it breaks pickling]
    :param verbose: Whether to print msg_run statements / lvl of reporting
    :param debug: Whether to print msg_debug statements / lvl of reporting
    :param warn: Whether to print msg_debug statements / lvl of warnings
    """
    # ----------------------------

    # self.out_stream = out_stream
    # self.err_stream = err_stream
    self.verbose = verbose
    self.debug = debug
    self.warn = warn
    self.flush = True
verbose = verbose instance-attribute
debug = debug instance-attribute
warn = warn instance-attribute
flush = True instance-attribute
msg_err(*x: str, end: str = '\n', delim: str = ' ', lvl: int = 0)

Messages for when something has broken or been called incorrectly

Parameters:

Name Type Description Default
x str

string(s) to be printed

()
end str

string to be printed at end of the msg

'\n'
delim str

string to be printed at delimiter between messages

' '
lvl int

logging level. int >=0

0
Source code in src/litmus_rm/logging.py
def msg_err(self, *x: str, end: str = '\n', delim: str = ' ', lvl: int = 0):
    """
    Messages for when something has broken or been called incorrectly
    :param x: string(s) to be printed
    :param end: string to be printed at end of the msg
    :param delim: string to be printed at delimiter between messages
    :param lvl: logging level. int >=0
    """
    lvl = max(lvl, 0)
    if self.warn >= lvl:
        for i, a in enumerate(x):
            print(a, file=sys.stderr, end=delim if i != len(x) else "", flush=False)
        print('', end=end, flush=self.flush)
    return
msg_run(*x: str, end: str = '\n', delim: str = ' ', lvl: int = 1)

Standard messages about when things are running

Parameters:

Name Type Description Default
x str

string(s) to be printed

()
end str

string to be printed at end of the msg

'\n'
delim str

string to be printed at delimiter between messages

' '
lvl int

logging level. int >=1

1
Source code in src/litmus_rm/logging.py
def msg_run(self, *x: str, end: str = '\n', delim: str = ' ', lvl: int = 1):
    """
    Standard messages about when things are running
    :param x: string(s) to be printed
    :param end: string to be printed at end of the msg
    :param delim: string to be printed at delimiter between messages
    :param lvl: logging level. int >=1
    """
    lvl = max(lvl, 1)
    if self.verbose >= lvl:
        for i, a in enumerate(x):
            print(a, file=sys.stdout, end=delim if i != len(x) else "", flush=False)
        print('', end=end, flush=self.flush)
    return
msg_debug(*x: str, end: str = '\n', delim: str = ' ', lvl: int = 1)

Explicit messages to help debug when things are behaving strangely

Parameters:

Name Type Description Default
x str

string(s) to be printed

()
end str

string to be printed at end of the msg

'\n'
delim str

string to be printed at delimiter between messages

' '
lvl int

logging level. int >=1

1
Source code in src/litmus_rm/logging.py
def msg_debug(self, *x: str, end: str = '\n', delim: str = ' ', lvl: int = 1):
    """
    Explicit messages to help debug when things are behaving strangely
    :param x: string(s) to be printed
    :param end: string to be printed at end of the msg
    :param delim: string to be printed at delimiter between messages
    :param lvl: logging level. int >=1
    """
    lvl = max(lvl, 1)
    if self.debug >= lvl:
        for i, a in enumerate(x):
            print(a, file=sys.stdout, end=delim if i != len(x) else "", flush=False)
        print('', end=end, flush=self.flush)
    return