Skip to content

litmus.logging

logging.py

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

logger(out_stream=sys.stdout, err_stream=sys.stderr, verbose: bool = True, debug: bool = False)

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

Parameters:

Name Type Description Default
out_stream

Stream to print run and debug messages to

stdout
err_stream

Stream to print error messages to

stderr
verbose bool

Whether to print msg_run statements

True
debug bool

Whether to print msg_debug statements

False
Source code in litmus/logging.py
16
17
18
19
20
21
22
23
24
25
26
27
28
def __init__(self, out_stream=sys.stdout, err_stream=sys.stderr, verbose: bool = True, debug: bool = False):
    """
    :param out_stream: Stream to print run and debug messages to
    :param err_stream: Stream to print error messages to
    :param verbose: Whether to print msg_run statements
    :param debug: Whether to print msg_debug statements
    """
    # ----------------------------

    self.out_stream = out_stream
    self.err_stream = err_stream
    self.verbose = verbose
    self.debug = debug
out_stream = out_stream instance-attribute
err_stream = err_stream instance-attribute
verbose = verbose instance-attribute
debug = debug instance-attribute
msg_err(*x: str, end='\n', delim=' ')

Messages for when something has broken or been called incorrectly

Source code in litmus/logging.py
32
33
34
35
36
37
38
39
40
41
def msg_err(self, *x: str, end='\n', delim=' '):
    """
    Messages for when something has broken or been called incorrectly
    """
    if True:
        for a in x:
            print(a, file=self.err_stream, end=delim)

    print(end, end='')
    return
msg_run(*x: str, end='\n', delim=' ')

Standard messages about when things are running

Source code in litmus/logging.py
43
44
45
46
47
48
49
50
51
52
def msg_run(self, *x: str, end='\n', delim=' '):
    """
    Standard messages about when things are running
    """
    if self.verbose:
        for a in x:
            print(a, file=self.out_stream, end=delim)

    print(end, end='')
    return
msg_verbose(*x: str, end='\n', delim=' ')

Explicit messages to help debug when things are behaving strangely

Source code in litmus/logging.py
54
55
56
57
58
59
60
61
62
63
def msg_verbose(self, *x: str, end='\n', delim=' '):
    """
    Explicit messages to help debug when things are behaving strangely
    """
    if self.debug:
        for a in x:
            print(a, file=self.out_stream, end=delim)

    print(end, end='')
    return