lib.logger Module

Logging Functions for Faceswap.

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

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) – If True new lines will be padded to appear in line with the log message, if False they will be left aligned

  • kwargs – Standard logging.Formatter keyword arguments

format(record: LogRecord) str

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

Parameters:

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

Return type:

The formatted log message

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

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 (LogRecord) – The incoming log record to be formatted for entry into the logger.

Return type:

The formatted log message

class lib.logger.FaceswapLogger(name, level=0)

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 – Standard logging arguments

  • kwargs – Standard logging key word arguments

Return type:

None

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 – Standard logging arguments

  • kwargs – Standard logging key word arguments

Return type:

None

class lib.logger.RollingBuffer

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

Return type:

None

class lib.logger.TorchWarningsFilter

Filter compilation warnings from Torch out of the console, but allow them to exist in the log

filter(record: LogRecord) bool

Filter specific Torch compile warnings from the console

Parameters:

record (LogRecord) – The incoming log record to check for filtering

Return type:

True if the record should be displayed

class lib.logger.TqdmHandler(stream=None)

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 (LogRecord) – The incoming log record to be formatted for entry into the logger.

Return type:

None

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.

Return type:

The filename of the file that contains the crash report

lib.logger.format_array(array: np.ndarray) str

Format arrays to be suitable for logging

Parameters:

array (np.ndarray) – The array to be formatted for logging

Return type:

String representation of an array for logging

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

Return type:

The numeric representation of the given loglevel

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 – 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) – Whether Faceswap is running in the GUI or not. Dictates where the stream handler should output messages to. Default: False

Return type:

None

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

Return type:

The locals information suitable for logging

Parameters:

locals_dict (dict[str, Any])

Functions

crash_log()

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.

format_array(array)

Format arrays to be suitable for logging

get_loglevel(loglevel)

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

log_setup(loglevel, log_file, command[, is_gui])

Set up logging for Faceswap.

parse_class_init(locals_dict)

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

Classes

ColoredFormatter(fmt[, pad_newlines])

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

FaceswapFormatter([fmt, datefmt, style, ...])

Overrides the standard logging.Formatter.

FaceswapLogger(name[, level])

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

RollingBuffer

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

TorchWarningsFilter()

Filter compilation warnings from Torch out of the console, but allow them to exist in the log

TqdmHandler([stream])

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.