logger module

Logging Functions for Faceswap.

class lib.logger.FaceswapFormatter(fmt=None, datefmt=None, style='%')

Bases: logging.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)

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)

Bases: logging.Logger

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

trace(msg, *args, **kwargs)

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, *args, **kwargs)

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: collections.deque

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

write(buffer)

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: logging.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)

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()

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)

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, command, is_gui=False)

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