ditk.logging

LoggingTerminalHandler

class ditk.logging.LoggingTerminalHandler(use_stdout: bool = False, level: Union[int, str] = 0)[source]
Overview:

A handler customized in ditk.

When DISABLE_RICH environment variable is set to non-empty, log will be printed to ordinary StreamHandler, otherwise rich.logging.RichHandler will be used.

__init__(use_stdout: bool = False, level: Union[int, str] = 0)[source]

Constructor of TerminalHandler.

Parameters:
  • use_stdout – Use sys.stdout instead of sys.stderr.

  • level – Log level.

emit(record: logging.LogRecord) → None[source]

Emit the log record to handler.

If DISABLE_RICH environment variable is set to non-empty, this method is equal to logging.StreamHandler.emit(), otherwise equals to rich.logging.RichHandler.emit().

LoggingFileHandler

class ditk.logging.LoggingFileHandler(filename: str, mode: str = 'a', encoding: Optional[str] = None, delay: bool = False, **kwargs)[source]
__init__(filename: str, mode: str = 'a', encoding: Optional[str] = None, delay: bool = False, **kwargs) → None[source]

Open the specified file and use it as the stream for logging.

emit(record)

Emit a record.

If the stream was not opened because ‘delay’ was specified in the constructor, open it before calling the superclass’s emit.

property file_path

Unique path of the file.

try_init_root

ditk.logging.try_init_root(level: Optional[Union[int, str]] = None) → logging.Logger[source]

getLogger

ditk.logging.getLogger(name: Optional[str] = None, level: Optional[Union[int, str]] = None, with_files: Optional[List[str]] = None) → logging.Logger[source]
Overview:

Get logging.Logger object, with terminal output and file output.

Parameters:
  • name – Name of logger.

  • level – Logging level of the loggers.

  • with_files – The files going to output.

Return logger:

Logger created.