console - console output
Helper methods for printing ANSI formatted output to a terminal and redirecting output to log file(s).
The console(3) module is a built in module available to all programs. It is responsible for printing messages with optional replacement parameters which are highlighted when the message is printed.
If either stdout or stderr is not a tty then formatting of the output message is not performed which means that when redirecting to a file the ANSI sequence is omitted and the string is passed with parameter replacement performed but no formatting.
The general syntax for printing output is:
console.info "message to print with %s information" "important";
%s substring in the main message will be highlighted and replaced with the string important, generating:
message to print with
To print to standard output use the following methods.
Prints an informational message.
Prints a log message. This method does not perform any formatting or print any program (or message type prefix) but does provide parameter replacement. This method is essentially just a wrapper for echo(1) that allows the use of parameter replacement and the log file redirection functionality.
To print to standard error use the following methods.
Prints a warning message.
Prints an error message.
Prints an error message followed by a stack trace of the current method call stack.
The console(3) module supports redirecting stdout/stderr to log file(s).
Redirect stdout to a log file and store stdout in file descriptor #3.
Close redirection of stdout, restoring stdout and closing file descriptor #3.
Redirect stderr to a log file and store stderr in file descriptor #4.
Close redirection of stderr, restoring stderr and closing file descriptor #4.
The console(3) module provides methods for exiting the program (optionally with a formatted message).
Marks the program as completed successfully (exiting with a zero exit code) and optionally prints a formatted message.
Exits the program with a non-zero exit code and optional error message. Note that the signature for this method differs from the general syntax for console(3) methods as it expects the first parameter to be the exit code.
The console(3) module parses the program options (but does not modify them) looking for the following options:
Do not perform any ANSI color or formatting modifications to the output.
See the globals-api(3) documentation.
You may also print a stack trace (without any preceeding error message) using the
console.trace method. Note that this method does not follow the general syntax for console(3) method invocations and accepts no parameters.
The number of replacement parameters must match exactly the number of
%s occurences in the message otherwise unexpected behaviour will occur.
console is written in bash and depends upon
bash >= 4.
console is copyright (c) 2012 muji http://xpm.io