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
| Attribute | Type | Description |
|---|---|---|
| splash_text | string = 'celery multi v{version}' | Template string for the banner message displayed when the logger initializes. |
| splash_context | dict | Dictionary containing template variables, such as version information, used to format the splash_text. |
| retcode | int = 0 | Final 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
| Name | Type | Description |
|---|---|---|
| stdout | file-like object | The primary output stream for standard messages |
| stderr | file-like object | The error output stream for warnings and failures |
| nosplash | boolean = False | Flag to suppress the display of the startup splash banner |
| quiet | boolean = False | Flag to suppress all non-essential output messages |
| verbose | boolean = False | Flag to enable detailed informational logging |
| no_color | boolean = False | Flag 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
| Name | Type | Description |
|---|---|---|
| m | string | The success message text to be displayed |
| newline | boolean = True | Whether to append a newline character at the end of the message |
| file | file-like object = null | Optional override for the output stream; defaults to stdout |
Returns
| Type | Description |
|---|---|
int | The 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
| Name | Type | Description |
|---|---|---|
| m | string | The message content to print |
| newline | boolean = True | Whether to append a newline character at the end of the message |
| file | file-like object = null | The 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
| Name | Type | Description |
|---|---|---|
| m | string | The error or warning message to display |
| newline | boolean = True | Whether to append a newline character at the end of the message |
| file | file-like object = null | Optional 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
| Name | Type | Description |
|---|---|---|
| msg | string = null | The specific error message to log before showing usage |
Returns
| Type | Description |
|---|---|
int | The 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
| Name | Type | Description |
|---|---|---|
| msg | string | The informational text to display |
| newline | boolean = True | Whether 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
| Name | Type | Description |
|---|---|---|
| msg | string | The message or object to be converted to a string and displayed |
| newline | boolean = True | Whether 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
| Type | Description |
|---|---|
object | A terminal coloring object that applies ANSI styles to strings |