create_logger(logger: Logger, file_log_level: int = 10, stream_log_level: int = 20, output_folder: str | None = None, name: str | None = None, other_loggers_names: list | str | None = None, other_loggers_file_log_level: int | None = None, other_loggers_stream_log_level: int | None = None) None[source]#

Create file and stream logger at the wanted level for the given logger.

  • If you have colorlog installed, it will produce colored logs.

  • If you do not give any output and name, it won’t create any file logger

It will also manage the log level of other specified logger that you give.

  • logger (logging.Logger) – Logger to create

  • file_log_level (int) – File log level

  • stream_log_level (int) – Stream log level

  • output_folder (str) – Output folder. Won’t create File logger if not specified

  • name (str) – Name of the log file, prefixed with the date and suffixed with _log. Can be None.

  • other_loggers_names (Union[str, list]) – Other existing logger to manage (setting the right format and log level)

  • other_loggers_file_log_level (int) – File log level for other loggers

  • other_loggers_stream_log_level (int) – Stream log level for other loggers


>>> logger = logging.getLogger("logger_test")
>>> create_logger(logger, logging.DEBUG, logging.INFO, "path/to/log", "log.txt")
2021-03-02 16:57:35 - [INFO] - MESSAGE
>>> # "logger_test" will also log DEBUG messages
>>> # to the "path/to/log/log.txt" file with the same format