ditk.logging

LoggingTerminalHandler

class ditk.logging.LoggingTerminalHandler(use_stdout: bool = False, level: 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: int | str = 0)[source]

Constructor of TerminalHandler.

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

  • level – Log level.

emit(record: 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: str | None = None, delay: bool = False, **kwargs)[source]
__init__(filename: str, mode: str = 'a', encoding: str | None = 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.

If stream is not open, current mode is ‘w’ and _closed=True, record will not be emitted (see Issue #42378).

property file_path: str

Unique path of the file.

try_init_root

ditk.logging.try_init_root(level: int | str | None = None) Logger[source]

getLogger

ditk.logging.getLogger(name: str | None = None, level: int | str | None = None, with_files: List[str] | None = None) 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.