Skip to main content

TermLogger

This class provides a specialized logging utility for terminal output, supporting standard streams, colored text, and verbosity levels. It includes methods for displaying splash screens, usage information, and formatted messages such as errors, notes, and status updates. The class manages exit codes and terminal configuration to ensure consistent command-line feedback.

Attributes

AttributeTypeDescription
splash_textstring = 'celery multi v{version}'Template string for the banner message displayed when the logger initializes.
splash_contextdictDictionary containing template variables, such as version information, used to format the splash_text.
retcodeint = 0Final exit code.

Methods


setup_terminal()

@classmethod
def setup_terminal(
stdout: file-like object,
stderr: file-like object,
nosplash: boolean = False,
quiet: boolean = False,
verbose: boolean = False,
no_color: boolean = False
)

Configures the terminal logging environment by setting output streams and verbosity levels.

Parameters

NameTypeDescription
stdoutfile-like objectThe primary output stream for standard messages
stderrfile-like objectThe error output stream for warnings and failures
nosplashboolean = FalseFlag to suppress the display of the startup splash banner
quietboolean = FalseFlag to suppress all non-essential output messages
verboseboolean = FalseFlag to enable detailed informational logging
no_colorboolean = FalseFlag to disable ANSI color codes in the output

ok()

@classmethod
def ok(
m: string,
newline: boolean = True,
file: file-like object = null
) - > int

Prints a success message to the standard output and returns the standard success exit code.

Parameters

NameTypeDescription
mstringThe success message text to be displayed
newlineboolean = TrueWhether to append a newline character at the end of the message
filefile-like object = nullOptional override for the output stream; defaults to stdout

Returns

TypeDescription
intThe EX_OK exit status code indicating successful execution

say()

@classmethod
def say(
m: string,
newline: boolean = True,
file: file-like object = null
)

Writes a message to the specified output stream or the configured stdout.

Parameters

NameTypeDescription
mstringThe message content to print
newlineboolean = TrueWhether to append a newline character at the end of the message
filefile-like object = nullThe specific stream to write to; defaults to the configured stdout

carp()

@classmethod
def carp(
m: string,
newline: boolean = True,
file: file-like object = null
)

Writes a message to the error stream (stderr) instead of standard output.

Parameters

NameTypeDescription
mstringThe error or warning message to display
newlineboolean = TrueWhether to append a newline character at the end of the message
filefile-like object = nullOptional override for the error stream; defaults to stderr

error()

@classmethod
def error(
msg: string = null
) - > int

Logs an error message if provided, displays command usage information, and returns a failure exit code.

Parameters

NameTypeDescription
msgstring = nullThe specific error message to log before showing usage

Returns

TypeDescription
intThe EX_FAILURE exit status code indicating an error occurred

info()

@classmethod
def info(
msg: string,
newline: boolean = True
)

Logs an informational message only if the logger is configured in verbose mode.

Parameters

NameTypeDescription
msgstringThe informational text to display
newlineboolean = TrueWhether to append a newline character at the end of the message

note()

@classmethod
def note(
msg: string,
newline: boolean = True
)

Logs a message to the output stream unless the logger is configured in quiet mode.

Parameters

NameTypeDescription
msgstringThe message or object to be converted to a string and displayed
newlineboolean = TrueWhether to append a newline character at the end of the message

usage()

@classmethod
def usage()

Displays the command-line usage instructions for the program.


splash()

@classmethod
def splash()

Displays the application splash banner in cyan text if splash output is not suppressed.


colored()

@classmethod
def colored() - > object

Provides a terminal color helper object based on the current color configuration.

Returns

TypeDescription
objectA terminal coloring object that applies ANSI styles to strings