logger module

Logging Functions for Faceswap.

class lib.logger.ColoredFormatter(fmt: str, pad_newlines: bool = False, **kwargs)

Bases: Formatter

Overrides the stand logging.Formatter to enable colored labels for message level labels on supported platforms

Parameters:
  • fmt (str) – The format string for the message as a whole

  • pad_newlines (bool, Optional) – If True new lines will be padded to appear in line with the log message, if False they will be left aligned

  • kwargs (dict) – Standard logging.Formatter keyword arguments

format(record: LogRecord) str

Color the log message level if supported otherwise return the standard log message.

Parameters:

record (logging.LogRecord) – The incoming log record to be formatted for entry into the logger.

Returns:

The formatted log message

Return type:

str

class lib.logger.FaceswapFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)

Bases: Formatter

Overrides the standard logging.Formatter.

Strip newlines from incoming log messages.

Rewrites some upstream warning messages to debug level to avoid spamming the console.

format(record: LogRecord) str

Strip new lines from log records and rewrite certain warning messages to debug level.

Parameters:

record (logging.LogRecord) – The incoming log record to be formatted for entry into the logger.

Returns:

The formatted log message

Return type:

str

class lib.logger.FaceswapLogger(name: str)

Bases: Logger

A standard logging.logger with additional “verbose” and “trace” levels added.

trace(msg: str, *args, **kwargs) None

Create a log message at severity level 5.

Parameters:
  • msg (str) – The log message to be recorded at Trace level

  • args (tuple) – Standard logging arguments

  • kwargs (dict) – Standard logging key word arguments

verbose(msg: str, *args, **kwargs) None

Create a log message at severity level 15.

Parameters:
  • msg (str) – The log message to be recorded at Verbose level

  • args (tuple) – Standard logging arguments

  • kwargs (dict) – Standard logging key word arguments

class lib.logger.RollingBuffer

Bases: deque

File-like that keeps a certain number of lines of text in memory for writing out to the crash log.

write(buffer: str) None

Splits lines from the incoming buffer and writes them out to the rolling buffer.

Parameters:

buffer (str) – The log messages to write to the rolling buffer

class lib.logger.TqdmHandler(stream=None)

Bases: StreamHandler

Overrides logging.StreamHandler to use tqdm.tqdm.write() rather than writing to sys.stderr() so that log messages do not mess up tqdm progress bars.

emit(record: LogRecord) None

Format the incoming message and pass to tqdm.tqdm.write().

Parameters:

record (logging.LogRecord) – The incoming log record to be formatted for entry into the logger.

lib.logger.crash_log() str

On a crash, write out the contents of _DEBUG_BUFFER() containing the last 100 lines of debug messages to a crash report in the root Faceswap folder.

Returns:

The filename of the file that contains the crash report

Return type:

str

lib.logger.get_loglevel(loglevel: str) int

Check whether a valid log level has been supplied, and return the numeric log level that corresponds to the given string level.

Parameters:

loglevel (str) – The loglevel that has been requested

Returns:

The numeric representation of the given loglevel

Return type:

int

lib.logger.log_setup(loglevel, log_file: str, command: str, is_gui: bool = False) None

Set up logging for Faceswap.

Sets up the root logger, the formatting for the crash logger and the file logger, and sets up the crash, file and stream log handlers.

Parameters:
  • loglevel (str) – The requested log level that Faceswap should be run at.

  • log_file (str) – The location of the log file to write Faceswap’s log to

  • command (str) – The Faceswap command that is being run. Used to dictate whether the log file should have “_gui” appended to the filename or not.

  • is_gui (bool, optional) – Whether Faceswap is running in the GUI or not. Dictates where the stream handler should output messages to. Default: False

lib.logger.parse_class_init(locals_dict: dict[str, Any]) str

Parse a locals dict from a class and return in a format suitable for logging :param locals_dict: A locals() dictionary from a newly initialized class :type locals_dict: dict[str, T.Any]

Returns:

The locals information suitable for logging

Return type:

str