metobs_toolkit.add_FileHandler#
- add_FileHandler(filepath: str | PathLike, setlvl: str = 'WARNING', logformat: str = 'LOG:: %(levelname)s - %(message)s', clearlog: bool = True) None[source]#
Add a FileHandler to the Toolkit logger.
A FileHandler directs the logs generated by the metobs_toolkit to a file.
- Parameters:
filepath (str | PathLike) – Path of the target log file.
setlvl ({"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}, optional) – The logger level for the FileHandler. See https://docs.python.org/3/library/logging.html#levels for more details. The default is “DEBUG”.
logformat (str, optional) – The format of the log messages. The default is “LOG:: %(levelname)s - %(message)s”.
clearlog (bool, optional) – If True, the trglogfile is cleared before adding the FileHandler. The default is True.
- Return type:
None
Notes
This function checks existing handlers to avoid duplicate FileHandlers for the same file. If a FileHandler already exists for the same file path with the same or more restrictive (higher) log level, no new handler is added. Log levels in order of restrictiveness: DEBUG < INFO < WARNING < ERROR < CRITICAL.