Logger Module#

The logger module provides logging functionality for the FTP server.

Custom logger setup for the thinFTP server.

This module defines a custom logging level called “SUCCESS”, provides colored log formatting for different levels, and supplies a helper function get_logger to configure a logger instance for use throughout the application.

thinftp.logger.success(self, message, *args, **kwargs)[source]#

Log a message with the custom SUCCESS level.

Parameters:
  • message (str) – The message to be logged.

  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

class thinftp.logger.Formatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]#

Bases: Formatter

Custom log formatter with ANSI color codes for console output.

Formats log messages with different colors depending on the level, improving readability during development or monitoring.

red = '\x1b[31m'#
bold_red = '\x1b[1;31m'#
yellow = '\x1b[93m'#
green = '\x1b[32m'#
gray = '\x1b[38;20m'#
bold = '\x1b[1m'#
reset = '\x1b[0m'#
FORMATS = {10: '\x1b[38;20m[%(asctime)s] [%(levelname)-8s] %(message)s\x1b[0m', 20: '\x1b[1m[%(asctime)s] [%(levelname)-8s] %(message)s\x1b[0m', 25: '\x1b[32m[%(asctime)s] [%(levelname)-8s] %(message)s\x1b[0m', 30: '\x1b[93m[%(asctime)s] [%(levelname)-8s] %(message)s\x1b[0m', 40: '\x1b[31m[%(asctime)s] [%(levelname)-8s] %(message)s\x1b[0m', 50: '\x1b[1;31m[%(asctime)s] [%(levelname)-8s] %(message)s\x1b[0m'}#
format(record)[source]#

Apply the appropriate color format to the log record.

Parameters:

record (LogRecord) – The log record to format.

Returns:

The formatted log message string.

Return type:

str

thinftp.logger.get_logger(name='thinFTP', debug=False)[source]#

Create and configure a logger with color output and custom SUCCESS level.

Parameters:
  • name (str) – Name of the logger. Defaults to “thinFTP”.

  • debug (bool) – If True, sets the log level to DEBUG; otherwise INFO.

Returns:

Configured logger instance.

Return type:

logging.Logger