docs: Add examples to documentation
This commit is contained in:
+19
-5
@@ -12,22 +12,36 @@ LOG_DEBUG=0
|
||||
#
|
||||
# @arg $1 string Log level to parse
|
||||
# @stdout numeric log level
|
||||
# @set LOG_LEVEL the global log level to use in the script
|
||||
# @example
|
||||
# # Parse lower case log level
|
||||
# parse_log_level "info"
|
||||
# @example
|
||||
# # Parse upper case log level
|
||||
# parse_log_level "ERROR"
|
||||
parse_log_level() {
|
||||
local level="$1"
|
||||
local parsed
|
||||
|
||||
case "${level}" in
|
||||
info | INFO) echo $LOG_INFO; ;;
|
||||
debug | DEBUG) echo $LOG_DEBUG; ;;
|
||||
warn | WARN) echo $LOG_WARN; ;;
|
||||
error | ERROR) echo $LOG_ERROR; ;;
|
||||
*) echo -1; ;;
|
||||
info | INFO) parsed=$LOG_INFO; ;;
|
||||
debug | DEBUG) parsed=$LOG_DEBUG; ;;
|
||||
warn | WARN) parsed=$LOG_WARN; ;;
|
||||
error | ERROR) parsed=$LOG_ERROR; ;;
|
||||
*) parsed=-1; ;;
|
||||
esac
|
||||
|
||||
export LOG_LEVEL="${parsed}"
|
||||
}
|
||||
|
||||
# @description Log output on a given level, checks if $LOG_LEVEL, if not set defaults to INFO
|
||||
# @arg $1 number Numeric log level
|
||||
# @arg $2 string Message to output
|
||||
# @stdout Formatted log message with ANSI color codes
|
||||
# @example
|
||||
# # Log a message on info level
|
||||
# log "$LOG_INFO" "this is a info message"
|
||||
# log "LOG_DEBUG" "i am only visible when \$LOG_LEVEL is debug"
|
||||
log() {
|
||||
local level="$1"
|
||||
local message="$2"
|
||||
|
||||
Reference in New Issue
Block a user