Package bioiain
Sub-modules
bioiain.alephbioiain.basebioiain.machinebioiain.symmetriesbioiain.toolsbioiain.utilitiesbioiain.visualisation
Functions
def log(level: int | str = 1, *args, **kwargs)-
Expand source code
def log(level:int|str=1, *args, **kwargs): """ Log a message and display it according to the given level if higher than environment variable "BI_VERBOSE". Builtin prints are always displayed. If unset BI_VERBOSE is set to 10. BI_VERBOSE == 0 displays only ERROR, WARNING and DEBUG messages. BI_VERBOSE == -1 display only ERROR. BI_VERBOSE == -1 display nothing. :param level: Verbose level: ERROR | WARNING | DEBUG | TITLE | HEADER | int :param args: args for print function :param kwargs: kwargs for print function """ v = int(os.environ.get("BI_VERBOSE", 10)) if type(level) is str: level = level.lower() if v > -2: if level == "error": if isinstance(kwargs.get("error", None), Exception): raise kwargs.get("error") elif kwargs.get("raise_exception", False): raise Exception(" ".join([str(a) for a in args])) else: print("\033[91m") print("ERROR: ", end="") print(*args, **kwargs) print("\033[0m") elif v > -1: if level == "warning": print("\033[93m",end="") print("WARNING: ", end="") print(*args, **kwargs) print("\033[0m",end="") elif level == "debug": print(*args, **kwargs) elif level == "title": print("\033]0;",end="") print(*args, **kwargs) print("\a",end="") elif v > 0: if level == 0 or level is None: print(*args, **kwargs) elif level == "start": tprint(*args, **kwargs) elif level == "header": sprint(*args, **kwargs) elif level == "end": eprint(*args, **kwargs) elif type(level) is int: if v >= level: print1(*args, space=2*level, **kwargs) else: print1("...", space=2 * level, **kwargs) else: print("Unknown log level: {}".format(repr(level))) print(*args, **kwargs)Log a message and display it according to the given level if higher than environment variable "BI_VERBOSE". Builtin prints are always displayed. If unset BI_VERBOSE is set to 10. BI_VERBOSE == 0 displays only ERROR, WARNING and DEBUG messages. BI_VERBOSE == -1 display only ERROR. BI_VERBOSE == -1 display nothing. :param level: Verbose level: ERROR | WARNING | DEBUG | TITLE | HEADER | int :param args: args for print function :param kwargs: kwargs for print function