Skip to main content

Logging

bashutils includes a fully SOSLS v2-compliant logging system as well as a crash handler, for bad days.

In the table below you can see all log levels bashutils supports, along with their ID and method. To print a message in a particular level, invoke it's method and pass the required arguments along.

NAME ID USAGE
Diagnostic 0 diag <str...:message>
Verbose 1 verb <str..:message>
Silent warning 2 sarn <str...:message>
Informational 3 info <str...:message>
Warning 4 warn <str...:message>
Error 5 error <str...:message>

Crash handling

bashutils includes a fully functional crash handler. It prints information about the operating system, environment, stack trace and of course the crash itself. And, if you wish, it will terminate the script with code 69.

To trigger a crash, simply invoke crash <bool:terminate> <str...:message>.

Customization

bashutils allows you to customize the logging system via environment variables.

BASHUTILS_LOGLEVEL

The desired minimum log level ID. Defaults to 3 (informational).

BASHUTILS_SUBSHELL

Subshell identifier. Increase this variable by 1 each time you invoke another script. Defaults to 1 (DO NOT LOWER THIS VALUE).