dosma.setup_logger
- dosma.setup_logger(output: Union[str, bool] = True, color=True, name='dosma', abbrev_name=None, stream_lvl=None, overwrite_handlers: bool = False)[source]
Initialize the dosma logger.
- Parameters
output (str | bool) – A file name or a directory to save log or a boolean. If
True, logs will save to the default dosma log location (dosma.utils.env.log_file_path()). IfNoneorFalse, logs will not be written to a file. This is not recommended. If a string and ends with “.txt” or “.log”, assumed to be a file name. Otherwise, logs will be saved to output/log.txt.color (bool) – If
True, logs printed to terminal (stdout) will be in color.name (str) – The root module name of this logger.
abbrev_name (str) – An abbreviation of the module, to avoid long names in logs. Set to “” to not log the root module in logs. By default, will abbreviate “dosma” to “dm” and leave other modules unchanged.
stream_lvl (int) – The level for logging to console. Defaults to
logging.DEBUGifdosma.utils.env.debug()isTrue, else defaults tologging.INFO.overwrite_handlers (bool) – It
Trueand logger with namenamehas logging handlers, these handlers will be removed before adding the new handlers. This is useful when to avoid having too many handlers for a logger.
- Returns
A logger.
- Return type
logging.Logger
Note
This method removes existing handlers from the logger.
Examples
>>> setup_logger() # how initializing logger is done most of the time >>> setup_logger("/path/to/save/dosma.log") # save log to particular file >>> setup_logger( ... stream_lvl=logging.WARNING, ... overwrite_handlers=True) # only prints warnings to console