Namespace src/Log

src/Log

Overview

Log namespace provides 2 kind of functions

  • Log::display* allows to display given message with given display level
  • Log::log* allows to log given message with given log level Log::display* functions automatically log the message too

file source src/Log/_.sh

Log::computeDuration

compute duration since last call to this function the result is set in following env variables. in ss.sss (seconds followed by milliseconds precision 3 decimals)

Function has no arguments.

Environment variables
  • DISPLAY_DURATION (int): (default 0) if 1 display elapsed time information between 2 info logs
Variables set
  • LOG_LAST_LOG_DATE_INIT (int): (default 1) set to 0 at first call, allows to detect reference log
  • LOG_LAST_DURATION_STR (String): the last duration displayed
  • LOG_LAST_LOG_DATE (String): the last log date that will be used to compute next diff

src/Log/displayDebug.sh

file source src/Log/displayDebug.sh

Log::displayDebug

Display message using debug color (gray)

Arguments
  • $1 (message:String): the message to display
Environment variables
  • DISPLAY_DURATION (int): (default 0) if 1 display elapsed time information between 2 info logs
  • LOG_CONTEXT (String): allows to contextualize the log

src/Log/displayError.sh

file source src/Log/displayError.sh

Log::displayError

Display message using error color (red)

Arguments
  • $1 (message:String): the message to display
Environment variables
  • DISPLAY_DURATION (int): (default 0) if 1 display elapsed time information between 2 info logs
  • LOG_CONTEXT (String): allows to contextualize the log

src/Log/displayHelp.sh

file source src/Log/displayHelp.sh

Log::displayHelp

Display message using info color (bg light blue/fg white)

Arguments
  • $1 (message:String): the message to display
Environment variables
  • DISPLAY_DURATION (int): (default 0) if 1 display elapsed time information between 2 info logs
  • LOG_CONTEXT (String): allows to contextualize the log

src/Log/displayInfo.sh

file source src/Log/displayInfo.sh

Log::displayInfo

Display message using info color (bg light blue/fg white)

Arguments
  • $1 (message:String): the message to display
Environment variables
  • DISPLAY_DURATION (int): (default 0) if 1 display elapsed time information between 2 info logs
  • LOG_CONTEXT (String): allows to contextualize the log

src/Log/displaySkipped.sh

file source src/Log/displaySkipped.sh

Log::displaySkipped

Display message using skip color (yellow)

Arguments
  • $1 (message:String): the message to display
Environment variables
  • DISPLAY_DURATION (int): (default 0) if 1 display elapsed time information between 2 info logs
  • LOG_CONTEXT (String): allows to contextualize the log

src/Log/displayStatus.sh

file source src/Log/displayStatus.sh

Log::displayStatus

Display message using info color (blue) but warning level

Arguments
  • $1 (message:String): the message to display
Environment variables
  • DISPLAY_DURATION (int): (default 0) if 1 display elapsed time information between 2 info logs
  • LOG_CONTEXT (String): allows to contextualize the log

src/Log/displaySuccess.sh

file source src/Log/displaySuccess.sh

Log::displaySuccess

Display message using success color (bg green/fg white)

Arguments
  • $1 (message:String): the message to display
Environment variables
  • DISPLAY_DURATION (int): (default 0) if 1 display elapsed time information between 2 info logs
  • LOG_CONTEXT (String): allows to contextualize the log

src/Log/displayWarning.sh

file source src/Log/displayWarning.sh

Log::displayWarning

Display message using warning color (yellow)

Arguments
  • $1 (message:String): the message to display
Environment variables
  • DISPLAY_DURATION (int): (default 0) if 1 display elapsed time information between 2 info logs
  • LOG_CONTEXT (String): allows to contextualize the log

src/Log/fatal.sh

file source src/Log/fatal.sh

Log::fatal

Display message using error color (red) and exit immediately with error status 1

Arguments
  • $1 (message:String): the message to display
Environment variables
  • DISPLAY_DURATION (int): (default 0) if 1 display elapsed time information between 2 info logs
  • LOG_CONTEXT (String): allows to contextualize the log

src/Log/getLevelText.sh

file source src/Log/getLevelText.sh

Log::getLevelText

Get the text representation of a log level

Arguments
  • $1 (level:String): the log level to convert
Exit codes
  • 1: if the level is invalid

src/Log/logDebug.sh

file source src/Log/logDebug.sh

Log::logDebug

log message to file

Arguments
  • $1 (message:String): the message to display

src/Log/logError.sh

file source src/Log/logError.sh

Log::logError

log message to file

Arguments
  • $1 (message:String): the message to display

src/Log/logFatal.sh

file source src/Log/logFatal.sh

Log::logFatal

log message to file

Arguments
  • $1 (message:String): the message to display

src/Log/logHelp.sh

file source src/Log/logHelp.sh

Log::logHelp

log message to file

Arguments
  • $1 (message:String): the message to display

src/Log/logInfo.sh

file source src/Log/logInfo.sh

Log::logInfo

log message to file

Arguments
  • $1 (message:String): the message to display

src/Log/logMessage.sh

file source src/Log/logMessage.sh

Log::logMessage

Internal: common log message

Example
[date]|[levelMsg]|message
2020-01-19 19:20:21|ERROR  |log error
2020-01-19 19:20:21|SKIPPED|log skipped
Arguments
  • $1 (levelMsg:String): message’s level description (eg: STATUS, ERROR, …)
  • $2 (msg:String): the message to display
Environment variables
  • BASH_FRAMEWORK_LOG_FILE (String): log file to use, do nothing if empty
  • BASH_FRAMEWORK_LOG_LEVEL (int): log level log only if > OFF or fatal messages
Output on stderr
  • diagnostics information is displayed
Requires
  • Env::requireLoad
  • Log::requireLoad

src/Log/logSkipped.sh

file source src/Log/logSkipped.sh

Log::logSkipped

log message to file

Arguments
  • $1 (message:String): the message to display

src/Log/logStatus.sh

file source src/Log/logStatus.sh

Log::logStatus

log message to file

Arguments
  • $1 (message:String): the message to display

src/Log/logSuccess.sh

file source src/Log/logSuccess.sh

Log::logSuccess

log message to file

Arguments
  • $1 (message:String): the message to display

src/Log/logWarning.sh

file source src/Log/logWarning.sh

Log::logWarning

log message to file

Arguments
  • $1 (message:String): the message to display

src/Log/requireLoad.sh

file source src/Log/requireLoad.sh

Log::requireLoad

activate or not Log::display* and Log::log* functions based on BASH_FRAMEWORK_DISPLAY_LEVEL and BASH_FRAMEWORK_LOG_LEVEL environment variables loaded by Env::requireLoad try to create log file and rotate it if necessary

Function has no arguments.

Environment variables
  • BASH_FRAMEWORK_DISPLAY_LEVEL (int):
  • BASH_FRAMEWORK_LOG_LEVEL (int):
  • BASH_FRAMEWORK_LOG_FILE (String):
  • BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION (int): do log rotation if > 0
Variables set
  • BASH_FRAMEWORK_LOG_LEVEL (int): to OFF level if BASH_FRAMEWORK_LOG_FILE is empty or not writable
Exit codes
  • 0: always successful
Output on stderr
  • diagnostics information about log file is displayed
Requires
  • Env::requireLoad
  • UI::requireTheme

src/Log/rotate.sh

file source src/Log/rotate.sh

Log::rotate

To be called before logging in the log file

Arguments
  • $1 (file:string): log file name
  • $2 (maxLogFilesCount:int): maximum number of log files
Or, if you want, you can alternatively use the GitHub discussion Q&A for feedback and questions.