#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# shellcheck source=/dev/null# source ./initLIBBASH_LOG_LEVEL=${LIBBASH_LOG_LEVEL:-"info"}export LIBBASH_LOG_LEVEL
# export LIBBASH_LOG_LEVEL=info#------------------------------ Private Functions ------------------------------function _lb_check_out(){localout="${1}"if[["${out}"=~ stdout|stderr ]];thenreturn0elseprintf"%s is not a valid output argument, it should be stdout|stderr\n""${out}"return1fi}function _lb_check_print(){localprint="${1}"if[["${print}"=~ printf|echo]];thenreturn0elseprintf"%s is not a valid print argument, it should be printf|echo\n""${print}"return1fi}function _lb_check_log_level(){locallevel="${1}"if[["${level}"=~ debug|info|warn|error|fatal ]];thenreturn0elseprintf"%s is not a valid LIBBASH_LOG_LEVEL, it should be debug|info|warn|error|fatal\n""${level}"return1fi}function _lb_log_msg(){declare -A LIBBASH_LOG_LEVELS=(\[debug]=1\[info]=2\[warn]=3\[error]=4\[fatal]=5\)declare -A BASH_LIB_LOG_COLOURS=(\[debug]="$(tput setaf 7)"\[info]="$(tput setaf 6)"\[warn]="$(tput setaf 3)"\[error]="$(tput setaf 1)"\[fatal]="$(tput setaf 7)"\)local bg_color
# Background color for fatalbg_color=$(tput setab 1)local normal
normal=$(tput sgr0)localruntime_log_level="${LIBBASH_LOG_LEVEL}"localwrite_log_level="${1}"localprint="${2}"localmsg="${3}"localout="${4:-stdout}"# Check our input arguments _lb_check_log_level "${runtime_log_level}" _lb_check_log_level "${write_log_level}" _lb_check_print "${print}" _lb_check_out "${out}"# Get the log level numberslocalruntime_level_num="${LIBBASH_LOG_LEVELS[${runtime_log_level}]}"localwrite_level_num="${LIBBASH_LOG_LEVELS[${write_log_level}]}"# Return if the write log level is lower than the runtime log levelif(( write_level_num < runtime_level_num ));thenreturnfi# Convert to upper casewrite_log_level_out="${write_log_level^^}"# Truncate to 4 characterswrite_log_level_out="${write_log_level_out::4}"# Set colorwrite_log_level_out="${BASH_LIB_LOG_COLOURS[${write_log_level}]}${write_log_level_out}${normal}"# Set fatal background colorif[["${write_log_level}"=="fatal"]];thenwrite_log_level_out="${bg_color}${write_log_level_out}${normal}"fi# Get the date and time formatlocal date_time
date_time=$(date +"%Y-%m-%dT%H:%M:%S%:z")# Create the message message="${write_log_level_out}[${date_time}] ${msg}"if[["${out}"=="stderr"]];thenif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"1>&2elseecho"${message}"1>&2fielseif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"elseecho"${message}"fifi}#------------------------------ Public Functions ------------------------------function lb_debugf(){ _lb_log_msg debug printf"${*}"}function lb_infof(){ _lb_log_msg info printf"${*}"}function lb_warnf(){ _lb_log_msg warn printf"${*}"}function lb_errorf(){ _lb_log_msg error printf"${*}"}function lb_fatalf(){ _lb_log_msg fatal printf"${*}"}function lb_debugln(){ _lb_log_msg debug echo"${*}"}function lb_infoln(){ _lb_log_msg info echo"${*}"}function lb_warnln(){ _lb_log_msg warn echo"${*}"}function lb_errorln(){ _lb_log_msg error echo"${*}"}function lb_fatalln(){ _lb_log_msg fatal echo"${*}"}
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# shellcheck source=/dev/null# source ./initLIBBASH_LOG_LEVEL=${LIBBASH_LOG_LEVEL:-"info"}export LIBBASH_LOG_LEVEL
# export LIBBASH_LOG_LEVEL=info#------------------------------ Private Functions ------------------------------function _lb_check_out(){localout="${1}"if[["${out}"=~ stdout|stderr ]];thenreturn0elseprintf"%s is not a valid output argument, it should be stdout|stderr\n""${out}"return1fi}function _lb_check_print(){localprint="${1}"if[["${print}"=~ printf|echo]];thenreturn0elseprintf"%s is not a valid print argument, it should be printf|echo\n""${print}"return1fi}function _lb_check_log_level(){locallevel="${1}"if[["${level}"=~ debug|info|warn|error|fatal ]];thenreturn0elseprintf"%s is not a valid LIBBASH_LOG_LEVEL, it should be debug|info|warn|error|fatal\n""${level}"return1fi}function _lb_log_msg(){declare -A LIBBASH_LOG_LEVELS=(\[debug]=1\[info]=2\[warn]=3\[error]=4\[fatal]=5\)declare -A BASH_LIB_LOG_COLOURS=(\[debug]="$(tput setaf 7)"\[info]="$(tput setaf 6)"\[warn]="$(tput setaf 3)"\[error]="$(tput setaf 1)"\[fatal]="$(tput setaf 7)"\)local bg_color
# Background color for fatalbg_color=$(tput setab 1)local normal
normal=$(tput sgr0)localruntime_log_level="${LIBBASH_LOG_LEVEL}"localwrite_log_level="${1}"localprint="${2}"localmsg="${3}"localout="${4:-stdout}"# Check our input arguments _lb_check_log_level "${runtime_log_level}" _lb_check_log_level "${write_log_level}" _lb_check_print "${print}" _lb_check_out "${out}"# Get the log level numberslocalruntime_level_num="${LIBBASH_LOG_LEVELS[${runtime_log_level}]}"localwrite_level_num="${LIBBASH_LOG_LEVELS[${write_log_level}]}"# Return if the write log level is lower than the runtime log levelif(( write_level_num < runtime_level_num ));thenreturnfi# Convert to upper casewrite_log_level_out="${write_log_level^^}"# Truncate to 4 characterswrite_log_level_out="${write_log_level_out::4}"# Set colorwrite_log_level_out="${BASH_LIB_LOG_COLOURS[${write_log_level}]}${write_log_level_out}${normal}"# Set fatal background colorif[["${write_log_level}"=="fatal"]];thenwrite_log_level_out="${bg_color}${write_log_level_out}${normal}"fi# Get the date and time formatlocal date_time
date_time=$(date +"%Y-%m-%dT%H:%M:%S%:z")# Create the message message="${write_log_level_out}[${date_time}] ${msg}"if[["${out}"=="stderr"]];thenif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"1>&2elseecho"${message}"1>&2fielseif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"elseecho"${message}"fifi}#------------------------------ Public Functions ------------------------------function lb_debugf(){ _lb_log_msg debug printf"${*}"}function lb_infof(){ _lb_log_msg info printf"${*}"}function lb_warnf(){ _lb_log_msg warn printf"${*}"}function lb_errorf(){ _lb_log_msg error printf"${*}"}function lb_fatalf(){ _lb_log_msg fatal printf"${*}"}function lb_debugln(){ _lb_log_msg debug echo"${*}"}function lb_infoln(){ _lb_log_msg info echo"${*}"}function lb_warnln(){ _lb_log_msg warn echo"${*}"}function lb_errorln(){ _lb_log_msg error echo"${*}"}function lb_fatalln(){ _lb_log_msg fatal echo"${*}"}
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# shellcheck source=/dev/null# source ./initLIBBASH_LOG_LEVEL=${LIBBASH_LOG_LEVEL:-"info"}export LIBBASH_LOG_LEVEL
# export LIBBASH_LOG_LEVEL=info#------------------------------ Private Functions ------------------------------function _lb_check_out(){localout="${1}"if[["${out}"=~ stdout|stderr ]];thenreturn0elseprintf"%s is not a valid output argument, it should be stdout|stderr\n""${out}"return1fi}function _lb_check_print(){localprint="${1}"if[["${print}"=~ printf|echo]];thenreturn0elseprintf"%s is not a valid print argument, it should be printf|echo\n""${print}"return1fi}function _lb_check_log_level(){locallevel="${1}"if[["${level}"=~ debug|info|warn|error|fatal ]];thenreturn0elseprintf"%s is not a valid LIBBASH_LOG_LEVEL, it should be debug|info|warn|error|fatal\n""${level}"return1fi}function _lb_log_msg(){declare -A LIBBASH_LOG_LEVELS=(\[debug]=1\[info]=2\[warn]=3\[error]=4\[fatal]=5\)declare -A BASH_LIB_LOG_COLOURS=(\[debug]="$(tput setaf 7)"\[info]="$(tput setaf 6)"\[warn]="$(tput setaf 3)"\[error]="$(tput setaf 1)"\[fatal]="$(tput setaf 7)"\)local bg_color
# Background color for fatalbg_color=$(tput setab 1)local normal
normal=$(tput sgr0)localruntime_log_level="${LIBBASH_LOG_LEVEL}"localwrite_log_level="${1}"localprint="${2}"localmsg="${3}"localout="${4:-stdout}"# Check our input arguments _lb_check_log_level "${runtime_log_level}" _lb_check_log_level "${write_log_level}" _lb_check_print "${print}" _lb_check_out "${out}"# Get the log level numberslocalruntime_level_num="${LIBBASH_LOG_LEVELS[${runtime_log_level}]}"localwrite_level_num="${LIBBASH_LOG_LEVELS[${write_log_level}]}"# Return if the write log level is lower than the runtime log levelif(( write_level_num < runtime_level_num ));thenreturnfi# Convert to upper casewrite_log_level_out="${write_log_level^^}"# Truncate to 4 characterswrite_log_level_out="${write_log_level_out::4}"# Set colorwrite_log_level_out="${BASH_LIB_LOG_COLOURS[${write_log_level}]}${write_log_level_out}${normal}"# Set fatal background colorif[["${write_log_level}"=="fatal"]];thenwrite_log_level_out="${bg_color}${write_log_level_out}${normal}"fi# Get the date and time formatlocal date_time
date_time=$(date +"%Y-%m-%dT%H:%M:%S%:z")# Create the message message="${write_log_level_out}[${date_time}] ${msg}"if[["${out}"=="stderr"]];thenif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"1>&2elseecho"${message}"1>&2fielseif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"elseecho"${message}"fifi}#------------------------------ Public Functions ------------------------------function lb_debugf(){ _lb_log_msg debug printf"${*}"}function lb_infof(){ _lb_log_msg info printf"${*}"}function lb_warnf(){ _lb_log_msg warn printf"${*}"}function lb_errorf(){ _lb_log_msg error printf"${*}"}function lb_fatalf(){ _lb_log_msg fatal printf"${*}"}function lb_debugln(){ _lb_log_msg debug echo"${*}"}function lb_infoln(){ _lb_log_msg info echo"${*}"}function lb_warnln(){ _lb_log_msg warn echo"${*}"}function lb_errorln(){ _lb_log_msg error echo"${*}"}function lb_fatalln(){ _lb_log_msg fatal echo"${*}"}
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# shellcheck source=/dev/null# source ./initLIBBASH_LOG_LEVEL=${LIBBASH_LOG_LEVEL:-"info"}export LIBBASH_LOG_LEVEL
# export LIBBASH_LOG_LEVEL=info#------------------------------ Private Functions ------------------------------function _lb_check_out(){localout="${1}"if[["${out}"=~ stdout|stderr ]];thenreturn0elseprintf"%s is not a valid output argument, it should be stdout|stderr\n""${out}"return1fi}function _lb_check_print(){localprint="${1}"if[["${print}"=~ printf|echo]];thenreturn0elseprintf"%s is not a valid print argument, it should be printf|echo\n""${print}"return1fi}function _lb_check_log_level(){locallevel="${1}"if[["${level}"=~ debug|info|warn|error|fatal ]];thenreturn0elseprintf"%s is not a valid LIBBASH_LOG_LEVEL, it should be debug|info|warn|error|fatal\n""${level}"return1fi}function _lb_log_msg(){declare -A LIBBASH_LOG_LEVELS=(\[debug]=1\[info]=2\[warn]=3\[error]=4\[fatal]=5\)declare -A BASH_LIB_LOG_COLOURS=(\[debug]="$(tput setaf 7)"\[info]="$(tput setaf 6)"\[warn]="$(tput setaf 3)"\[error]="$(tput setaf 1)"\[fatal]="$(tput setaf 7)"\)local bg_color
# Background color for fatalbg_color=$(tput setab 1)local normal
normal=$(tput sgr0)localruntime_log_level="${LIBBASH_LOG_LEVEL}"localwrite_log_level="${1}"localprint="${2}"localmsg="${3}"localout="${4:-stdout}"# Check our input arguments _lb_check_log_level "${runtime_log_level}" _lb_check_log_level "${write_log_level}" _lb_check_print "${print}" _lb_check_out "${out}"# Get the log level numberslocalruntime_level_num="${LIBBASH_LOG_LEVELS[${runtime_log_level}]}"localwrite_level_num="${LIBBASH_LOG_LEVELS[${write_log_level}]}"# Return if the write log level is lower than the runtime log levelif(( write_level_num < runtime_level_num ));thenreturnfi# Convert to upper casewrite_log_level_out="${write_log_level^^}"# Truncate to 4 characterswrite_log_level_out="${write_log_level_out::4}"# Set colorwrite_log_level_out="${BASH_LIB_LOG_COLOURS[${write_log_level}]}${write_log_level_out}${normal}"# Set fatal background colorif[["${write_log_level}"=="fatal"]];thenwrite_log_level_out="${bg_color}${write_log_level_out}${normal}"fi# Get the date and time formatlocal date_time
date_time=$(date +"%Y-%m-%dT%H:%M:%S%:z")# Create the message message="${write_log_level_out}[${date_time}] ${msg}"if[["${out}"=="stderr"]];thenif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"1>&2elseecho"${message}"1>&2fielseif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"elseecho"${message}"fifi}#------------------------------ Public Functions ------------------------------function lb_debugf(){ _lb_log_msg debug printf"${*}"}function lb_infof(){ _lb_log_msg info printf"${*}"}function lb_warnf(){ _lb_log_msg warn printf"${*}"}function lb_errorf(){ _lb_log_msg error printf"${*}"}function lb_fatalf(){ _lb_log_msg fatal printf"${*}"}function lb_debugln(){ _lb_log_msg debug echo"${*}"}function lb_infoln(){ _lb_log_msg info echo"${*}"}function lb_warnln(){ _lb_log_msg warn echo"${*}"}function lb_errorln(){ _lb_log_msg error echo"${*}"}function lb_fatalln(){ _lb_log_msg fatal echo"${*}"}
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# shellcheck source=/dev/null# source ./initLIBBASH_LOG_LEVEL=${LIBBASH_LOG_LEVEL:-"info"}export LIBBASH_LOG_LEVEL
# export LIBBASH_LOG_LEVEL=info#------------------------------ Private Functions ------------------------------function _lb_check_out(){localout="${1}"if[["${out}"=~ stdout|stderr ]];thenreturn0elseprintf"%s is not a valid output argument, it should be stdout|stderr\n""${out}"return1fi}function _lb_check_print(){localprint="${1}"if[["${print}"=~ printf|echo]];thenreturn0elseprintf"%s is not a valid print argument, it should be printf|echo\n""${print}"return1fi}function _lb_check_log_level(){locallevel="${1}"if[["${level}"=~ debug|info|warn|error|fatal ]];thenreturn0elseprintf"%s is not a valid LIBBASH_LOG_LEVEL, it should be debug|info|warn|error|fatal\n""${level}"return1fi}function _lb_log_msg(){declare -A LIBBASH_LOG_LEVELS=(\[debug]=1\[info]=2\[warn]=3\[error]=4\[fatal]=5\)declare -A BASH_LIB_LOG_COLOURS=(\[debug]="$(tput setaf 7)"\[info]="$(tput setaf 6)"\[warn]="$(tput setaf 3)"\[error]="$(tput setaf 1)"\[fatal]="$(tput setaf 7)"\)local bg_color
# Background color for fatalbg_color=$(tput setab 1)local normal
normal=$(tput sgr0)localruntime_log_level="${LIBBASH_LOG_LEVEL}"localwrite_log_level="${1}"localprint="${2}"localmsg="${3}"localout="${4:-stdout}"# Check our input arguments _lb_check_log_level "${runtime_log_level}" _lb_check_log_level "${write_log_level}" _lb_check_print "${print}" _lb_check_out "${out}"# Get the log level numberslocalruntime_level_num="${LIBBASH_LOG_LEVELS[${runtime_log_level}]}"localwrite_level_num="${LIBBASH_LOG_LEVELS[${write_log_level}]}"# Return if the write log level is lower than the runtime log levelif(( write_level_num < runtime_level_num ));thenreturnfi# Convert to upper casewrite_log_level_out="${write_log_level^^}"# Truncate to 4 characterswrite_log_level_out="${write_log_level_out::4}"# Set colorwrite_log_level_out="${BASH_LIB_LOG_COLOURS[${write_log_level}]}${write_log_level_out}${normal}"# Set fatal background colorif[["${write_log_level}"=="fatal"]];thenwrite_log_level_out="${bg_color}${write_log_level_out}${normal}"fi# Get the date and time formatlocal date_time
date_time=$(date +"%Y-%m-%dT%H:%M:%S%:z")# Create the message message="${write_log_level_out}[${date_time}] ${msg}"if[["${out}"=="stderr"]];thenif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"1>&2elseecho"${message}"1>&2fielseif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"elseecho"${message}"fifi}#------------------------------ Public Functions ------------------------------function lb_debugf(){ _lb_log_msg debug printf"${*}"}function lb_infof(){ _lb_log_msg info printf"${*}"}function lb_warnf(){ _lb_log_msg warn printf"${*}"}function lb_errorf(){ _lb_log_msg error printf"${*}"}function lb_fatalf(){ _lb_log_msg fatal printf"${*}"}function lb_debugln(){ _lb_log_msg debug echo"${*}"}function lb_infoln(){ _lb_log_msg info echo"${*}"}function lb_warnln(){ _lb_log_msg warn echo"${*}"}function lb_errorln(){ _lb_log_msg error echo"${*}"}function lb_fatalln(){ _lb_log_msg fatal echo"${*}"}
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# shellcheck source=/dev/null# source ./initLIBBASH_LOG_LEVEL=${LIBBASH_LOG_LEVEL:-"info"}export LIBBASH_LOG_LEVEL
# export LIBBASH_LOG_LEVEL=info#------------------------------ Private Functions ------------------------------function _lb_check_out(){localout="${1}"if[["${out}"=~ stdout|stderr ]];thenreturn0elseprintf"%s is not a valid output argument, it should be stdout|stderr\n""${out}"return1fi}function _lb_check_print(){localprint="${1}"if[["${print}"=~ printf|echo]];thenreturn0elseprintf"%s is not a valid print argument, it should be printf|echo\n""${print}"return1fi}function _lb_check_log_level(){locallevel="${1}"if[["${level}"=~ debug|info|warn|error|fatal ]];thenreturn0elseprintf"%s is not a valid LIBBASH_LOG_LEVEL, it should be debug|info|warn|error|fatal\n""${level}"return1fi}function _lb_log_msg(){declare -A LIBBASH_LOG_LEVELS=(\[debug]=1\[info]=2\[warn]=3\[error]=4\[fatal]=5\)declare -A BASH_LIB_LOG_COLOURS=(\[debug]="$(tput setaf 7)"\[info]="$(tput setaf 6)"\[warn]="$(tput setaf 3)"\[error]="$(tput setaf 1)"\[fatal]="$(tput setaf 7)"\)local bg_color
# Background color for fatalbg_color=$(tput setab 1)local normal
normal=$(tput sgr0)localruntime_log_level="${LIBBASH_LOG_LEVEL}"localwrite_log_level="${1}"localprint="${2}"localmsg="${3}"localout="${4:-stdout}"# Check our input arguments _lb_check_log_level "${runtime_log_level}" _lb_check_log_level "${write_log_level}" _lb_check_print "${print}" _lb_check_out "${out}"# Get the log level numberslocalruntime_level_num="${LIBBASH_LOG_LEVELS[${runtime_log_level}]}"localwrite_level_num="${LIBBASH_LOG_LEVELS[${write_log_level}]}"# Return if the write log level is lower than the runtime log levelif(( write_level_num < runtime_level_num ));thenreturnfi# Convert to upper casewrite_log_level_out="${write_log_level^^}"# Truncate to 4 characterswrite_log_level_out="${write_log_level_out::4}"# Set colorwrite_log_level_out="${BASH_LIB_LOG_COLOURS[${write_log_level}]}${write_log_level_out}${normal}"# Set fatal background colorif[["${write_log_level}"=="fatal"]];thenwrite_log_level_out="${bg_color}${write_log_level_out}${normal}"fi# Get the date and time formatlocal date_time
date_time=$(date +"%Y-%m-%dT%H:%M:%S%:z")# Create the message message="${write_log_level_out}[${date_time}] ${msg}"if[["${out}"=="stderr"]];thenif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"1>&2elseecho"${message}"1>&2fielseif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"elseecho"${message}"fifi}#------------------------------ Public Functions ------------------------------function lb_debugf(){ _lb_log_msg debug printf"${*}"}function lb_infof(){ _lb_log_msg info printf"${*}"}function lb_warnf(){ _lb_log_msg warn printf"${*}"}function lb_errorf(){ _lb_log_msg error printf"${*}"}function lb_fatalf(){ _lb_log_msg fatal printf"${*}"}function lb_debugln(){ _lb_log_msg debug echo"${*}"}function lb_infoln(){ _lb_log_msg info echo"${*}"}function lb_warnln(){ _lb_log_msg warn echo"${*}"}function lb_errorln(){ _lb_log_msg error echo"${*}"}function lb_fatalln(){ _lb_log_msg fatal echo"${*}"}
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# shellcheck source=/dev/null# source ./initLIBBASH_LOG_LEVEL=${LIBBASH_LOG_LEVEL:-"info"}export LIBBASH_LOG_LEVEL
# export LIBBASH_LOG_LEVEL=info#------------------------------ Private Functions ------------------------------function _lb_check_out(){localout="${1}"if[["${out}"=~ stdout|stderr ]];thenreturn0elseprintf"%s is not a valid output argument, it should be stdout|stderr\n""${out}"return1fi}function _lb_check_print(){localprint="${1}"if[["${print}"=~ printf|echo]];thenreturn0elseprintf"%s is not a valid print argument, it should be printf|echo\n""${print}"return1fi}function _lb_check_log_level(){locallevel="${1}"if[["${level}"=~ debug|info|warn|error|fatal ]];thenreturn0elseprintf"%s is not a valid LIBBASH_LOG_LEVEL, it should be debug|info|warn|error|fatal\n""${level}"return1fi}function _lb_log_msg(){declare -A LIBBASH_LOG_LEVELS=(\[debug]=1\[info]=2\[warn]=3\[error]=4\[fatal]=5\)declare -A BASH_LIB_LOG_COLOURS=(\[debug]="$(tput setaf 7)"\[info]="$(tput setaf 6)"\[warn]="$(tput setaf 3)"\[error]="$(tput setaf 1)"\[fatal]="$(tput setaf 7)"\)local bg_color
# Background color for fatalbg_color=$(tput setab 1)local normal
normal=$(tput sgr0)localruntime_log_level="${LIBBASH_LOG_LEVEL}"localwrite_log_level="${1}"localprint="${2}"localmsg="${3}"localout="${4:-stdout}"# Check our input arguments _lb_check_log_level "${runtime_log_level}" _lb_check_log_level "${write_log_level}" _lb_check_print "${print}" _lb_check_out "${out}"# Get the log level numberslocalruntime_level_num="${LIBBASH_LOG_LEVELS[${runtime_log_level}]}"localwrite_level_num="${LIBBASH_LOG_LEVELS[${write_log_level}]}"# Return if the write log level is lower than the runtime log levelif(( write_level_num < runtime_level_num ));thenreturnfi# Convert to upper casewrite_log_level_out="${write_log_level^^}"# Truncate to 4 characterswrite_log_level_out="${write_log_level_out::4}"# Set colorwrite_log_level_out="${BASH_LIB_LOG_COLOURS[${write_log_level}]}${write_log_level_out}${normal}"# Set fatal background colorif[["${write_log_level}"=="fatal"]];thenwrite_log_level_out="${bg_color}${write_log_level_out}${normal}"fi# Get the date and time formatlocal date_time
date_time=$(date +"%Y-%m-%dT%H:%M:%S%:z")# Create the message message="${write_log_level_out}[${date_time}] ${msg}"if[["${out}"=="stderr"]];thenif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"1>&2elseecho"${message}"1>&2fielseif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"elseecho"${message}"fifi}#------------------------------ Public Functions ------------------------------function lb_debugf(){ _lb_log_msg debug printf"${*}"}function lb_infof(){ _lb_log_msg info printf"${*}"}function lb_warnf(){ _lb_log_msg warn printf"${*}"}function lb_errorf(){ _lb_log_msg error printf"${*}"}function lb_fatalf(){ _lb_log_msg fatal printf"${*}"}function lb_debugln(){ _lb_log_msg debug echo"${*}"}function lb_infoln(){ _lb_log_msg info echo"${*}"}function lb_warnln(){ _lb_log_msg warn echo"${*}"}function lb_errorln(){ _lb_log_msg error echo"${*}"}function lb_fatalln(){ _lb_log_msg fatal echo"${*}"}
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# shellcheck source=/dev/null# source ./initLIBBASH_LOG_LEVEL=${LIBBASH_LOG_LEVEL:-"info"}export LIBBASH_LOG_LEVEL
# export LIBBASH_LOG_LEVEL=info#------------------------------ Private Functions ------------------------------function _lb_check_out(){localout="${1}"if[["${out}"=~ stdout|stderr ]];thenreturn0elseprintf"%s is not a valid output argument, it should be stdout|stderr\n""${out}"return1fi}function _lb_check_print(){localprint="${1}"if[["${print}"=~ printf|echo]];thenreturn0elseprintf"%s is not a valid print argument, it should be printf|echo\n""${print}"return1fi}function _lb_check_log_level(){locallevel="${1}"if[["${level}"=~ debug|info|warn|error|fatal ]];thenreturn0elseprintf"%s is not a valid LIBBASH_LOG_LEVEL, it should be debug|info|warn|error|fatal\n""${level}"return1fi}function _lb_log_msg(){declare -A LIBBASH_LOG_LEVELS=(\[debug]=1\[info]=2\[warn]=3\[error]=4\[fatal]=5\)declare -A BASH_LIB_LOG_COLOURS=(\[debug]="$(tput setaf 7)"\[info]="$(tput setaf 6)"\[warn]="$(tput setaf 3)"\[error]="$(tput setaf 1)"\[fatal]="$(tput setaf 7)"\)local bg_color
# Background color for fatalbg_color=$(tput setab 1)local normal
normal=$(tput sgr0)localruntime_log_level="${LIBBASH_LOG_LEVEL}"localwrite_log_level="${1}"localprint="${2}"localmsg="${3}"localout="${4:-stdout}"# Check our input arguments _lb_check_log_level "${runtime_log_level}" _lb_check_log_level "${write_log_level}" _lb_check_print "${print}" _lb_check_out "${out}"# Get the log level numberslocalruntime_level_num="${LIBBASH_LOG_LEVELS[${runtime_log_level}]}"localwrite_level_num="${LIBBASH_LOG_LEVELS[${write_log_level}]}"# Return if the write log level is lower than the runtime log levelif(( write_level_num < runtime_level_num ));thenreturnfi# Convert to upper casewrite_log_level_out="${write_log_level^^}"# Truncate to 4 characterswrite_log_level_out="${write_log_level_out::4}"# Set colorwrite_log_level_out="${BASH_LIB_LOG_COLOURS[${write_log_level}]}${write_log_level_out}${normal}"# Set fatal background colorif[["${write_log_level}"=="fatal"]];thenwrite_log_level_out="${bg_color}${write_log_level_out}${normal}"fi# Get the date and time formatlocal date_time
date_time=$(date +"%Y-%m-%dT%H:%M:%S%:z")# Create the message message="${write_log_level_out}[${date_time}] ${msg}"if[["${out}"=="stderr"]];thenif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"1>&2elseecho"${message}"1>&2fielseif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"elseecho"${message}"fifi}#------------------------------ Public Functions ------------------------------function lb_debugf(){ _lb_log_msg debug printf"${*}"}function lb_infof(){ _lb_log_msg info printf"${*}"}function lb_warnf(){ _lb_log_msg warn printf"${*}"}function lb_errorf(){ _lb_log_msg error printf"${*}"}function lb_fatalf(){ _lb_log_msg fatal printf"${*}"}function lb_debugln(){ _lb_log_msg debug echo"${*}"}function lb_infoln(){ _lb_log_msg info echo"${*}"}function lb_warnln(){ _lb_log_msg warn echo"${*}"}function lb_errorln(){ _lb_log_msg error echo"${*}"}function lb_fatalln(){ _lb_log_msg fatal echo"${*}"}
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# shellcheck source=/dev/null# source ./initLIBBASH_LOG_LEVEL=${LIBBASH_LOG_LEVEL:-"info"}export LIBBASH_LOG_LEVEL
# export LIBBASH_LOG_LEVEL=info#------------------------------ Private Functions ------------------------------function _lb_check_out(){localout="${1}"if[["${out}"=~ stdout|stderr ]];thenreturn0elseprintf"%s is not a valid output argument, it should be stdout|stderr\n""${out}"return1fi}function _lb_check_print(){localprint="${1}"if[["${print}"=~ printf|echo]];thenreturn0elseprintf"%s is not a valid print argument, it should be printf|echo\n""${print}"return1fi}function _lb_check_log_level(){locallevel="${1}"if[["${level}"=~ debug|info|warn|error|fatal ]];thenreturn0elseprintf"%s is not a valid LIBBASH_LOG_LEVEL, it should be debug|info|warn|error|fatal\n""${level}"return1fi}function _lb_log_msg(){declare -A LIBBASH_LOG_LEVELS=(\[debug]=1\[info]=2\[warn]=3\[error]=4\[fatal]=5\)declare -A BASH_LIB_LOG_COLOURS=(\[debug]="$(tput setaf 7)"\[info]="$(tput setaf 6)"\[warn]="$(tput setaf 3)"\[error]="$(tput setaf 1)"\[fatal]="$(tput setaf 7)"\)local bg_color
# Background color for fatalbg_color=$(tput setab 1)local normal
normal=$(tput sgr0)localruntime_log_level="${LIBBASH_LOG_LEVEL}"localwrite_log_level="${1}"localprint="${2}"localmsg="${3}"localout="${4:-stdout}"# Check our input arguments _lb_check_log_level "${runtime_log_level}" _lb_check_log_level "${write_log_level}" _lb_check_print "${print}" _lb_check_out "${out}"# Get the log level numberslocalruntime_level_num="${LIBBASH_LOG_LEVELS[${runtime_log_level}]}"localwrite_level_num="${LIBBASH_LOG_LEVELS[${write_log_level}]}"# Return if the write log level is lower than the runtime log levelif(( write_level_num < runtime_level_num ));thenreturnfi# Convert to upper casewrite_log_level_out="${write_log_level^^}"# Truncate to 4 characterswrite_log_level_out="${write_log_level_out::4}"# Set colorwrite_log_level_out="${BASH_LIB_LOG_COLOURS[${write_log_level}]}${write_log_level_out}${normal}"# Set fatal background colorif[["${write_log_level}"=="fatal"]];thenwrite_log_level_out="${bg_color}${write_log_level_out}${normal}"fi# Get the date and time formatlocal date_time
date_time=$(date +"%Y-%m-%dT%H:%M:%S%:z")# Create the message message="${write_log_level_out}[${date_time}] ${msg}"if[["${out}"=="stderr"]];thenif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"1>&2elseecho"${message}"1>&2fielseif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"elseecho"${message}"fifi}#------------------------------ Public Functions ------------------------------function lb_debugf(){ _lb_log_msg debug printf"${*}"}function lb_infof(){ _lb_log_msg info printf"${*}"}function lb_warnf(){ _lb_log_msg warn printf"${*}"}function lb_errorf(){ _lb_log_msg error printf"${*}"}function lb_fatalf(){ _lb_log_msg fatal printf"${*}"}function lb_debugln(){ _lb_log_msg debug echo"${*}"}function lb_infoln(){ _lb_log_msg info echo"${*}"}function lb_warnln(){ _lb_log_msg warn echo"${*}"}function lb_errorln(){ _lb_log_msg error echo"${*}"}function lb_fatalln(){ _lb_log_msg fatal echo"${*}"}
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# shellcheck source=/dev/null# source ./initLIBBASH_LOG_LEVEL=${LIBBASH_LOG_LEVEL:-"info"}export LIBBASH_LOG_LEVEL
# export LIBBASH_LOG_LEVEL=info#------------------------------ Private Functions ------------------------------function _lb_check_out(){localout="${1}"if[["${out}"=~ stdout|stderr ]];thenreturn0elseprintf"%s is not a valid output argument, it should be stdout|stderr\n""${out}"return1fi}function _lb_check_print(){localprint="${1}"if[["${print}"=~ printf|echo]];thenreturn0elseprintf"%s is not a valid print argument, it should be printf|echo\n""${print}"return1fi}function _lb_check_log_level(){locallevel="${1}"if[["${level}"=~ debug|info|warn|error|fatal ]];thenreturn0elseprintf"%s is not a valid LIBBASH_LOG_LEVEL, it should be debug|info|warn|error|fatal\n""${level}"return1fi}function _lb_log_msg(){declare -A LIBBASH_LOG_LEVELS=(\[debug]=1\[info]=2\[warn]=3\[error]=4\[fatal]=5\)declare -A BASH_LIB_LOG_COLOURS=(\[debug]="$(tput setaf 7)"\[info]="$(tput setaf 6)"\[warn]="$(tput setaf 3)"\[error]="$(tput setaf 1)"\[fatal]="$(tput setaf 7)"\)local bg_color
# Background color for fatalbg_color=$(tput setab 1)local normal
normal=$(tput sgr0)localruntime_log_level="${LIBBASH_LOG_LEVEL}"localwrite_log_level="${1}"localprint="${2}"localmsg="${3}"localout="${4:-stdout}"# Check our input arguments _lb_check_log_level "${runtime_log_level}" _lb_check_log_level "${write_log_level}" _lb_check_print "${print}" _lb_check_out "${out}"# Get the log level numberslocalruntime_level_num="${LIBBASH_LOG_LEVELS[${runtime_log_level}]}"localwrite_level_num="${LIBBASH_LOG_LEVELS[${write_log_level}]}"# Return if the write log level is lower than the runtime log levelif(( write_level_num < runtime_level_num ));thenreturnfi# Convert to upper casewrite_log_level_out="${write_log_level^^}"# Truncate to 4 characterswrite_log_level_out="${write_log_level_out::4}"# Set colorwrite_log_level_out="${BASH_LIB_LOG_COLOURS[${write_log_level}]}${write_log_level_out}${normal}"# Set fatal background colorif[["${write_log_level}"=="fatal"]];thenwrite_log_level_out="${bg_color}${write_log_level_out}${normal}"fi# Get the date and time formatlocal date_time
date_time=$(date +"%Y-%m-%dT%H:%M:%S%:z")# Create the message message="${write_log_level_out}[${date_time}] ${msg}"if[["${out}"=="stderr"]];thenif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"1>&2elseecho"${message}"1>&2fielseif[["${print}"=="printf"]];then# shellcheck disable=SC2059printf"${message}"elseecho"${message}"fifi}#------------------------------ Public Functions ------------------------------function lb_debugf(){ _lb_log_msg debug printf"${*}"}function lb_infof(){ _lb_log_msg info printf"${*}"}function lb_warnf(){ _lb_log_msg warn printf"${*}"}function lb_errorf(){ _lb_log_msg error printf"${*}"}function lb_fatalf(){ _lb_log_msg fatal printf"${*}"}function lb_debugln(){ _lb_log_msg debug echo"${*}"}function lb_infoln(){ _lb_log_msg info echo"${*}"}function lb_warnln(){ _lb_log_msg warn echo"${*}"}function lb_errorln(){ _lb_log_msg error echo"${*}"}function lb_fatalln(){ _lb_log_msg fatal echo"${*}"}