#!/bin/bash # # Library for logging functions # Constants RESET='\033[0m' RED='\033[38;5;1m' GREEN='\033[38;5;2m' YELLOW='\033[38;5;3m' MAGENTA='\033[38;5;5m' CYAN='\033[38;5;6m' # Functions ######################## # Print to STDERR # Arguments: # Message to print # Returns: # None ######################### stderr_print() { # 'is_boolean_yes' is defined in libvalidations.sh, but depends on this file so we cannot source it local -r bool="${BITNAMI_QUIET:-false}" # comparison is performed without regard to the case of alphabetic characters shopt -s nocasematch if ! [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then printf "%b\\n" "${*}" >&2 fi } ######################## # Log message # Arguments: # Message to log # Returns: # None ######################### log() { stderr_print "${CYAN}${MODULE:-} ${MAGENTA}$(date "+%T.%2N ")${RESET}${*}" } ######################## # Log an 'info' message # Arguments: # Message to log # Returns: # None ######################### info() { log "${GREEN}INFO ${RESET} ==> ${*}" } ######################## # Log message # Arguments: # Message to log # Returns: # None ######################### warn() { log "${YELLOW}WARN ${RESET} ==> ${*}" } ######################## # Log an 'error' message # Arguments: # Message to log # Returns: # None ######################### error() { log "${RED}ERROR${RESET} ==> ${*}" } ######################## # Log a 'debug' message # Globals: # BITNAMI_DEBUG # Arguments: # None # Returns: # None ######################### debug() { # 'is_boolean_yes' is defined in libvalidations.sh, but depends on this file so we cannot source it local -r bool="${BITNAMI_DEBUG:-false}" # comparison is performed without regard to the case of alphabetic characters shopt -s nocasematch if [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then log "${MAGENTA}DEBUG${RESET} ==> ${*}" fi }