2 # vim:noet:sw=4:ts=4:ft=sh
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 [ -n "$__AUTOCOM_LIB_LOG_INC__" ] && return || __AUTOCOM_LIB_LOG_INC__=1
20 LOGGING_TIMESTAMP_FORMAT='%b %d %H:%M:%S'
24 local fmt="%7s : ${1}%s\n"
26 [ -n "${LOGGING_TIMESTAMPS}" -a "${LOGGING_TIMESTAMPS}" != "0" ] \
27 && printf -v fmt "%(${LOGGING_TIMESTAMP_FORMAT})T %s" -1 "${fmt}"
35 local fmt="$(_logging_fmt "${1}")"
40 [ -n "${LOGGING_SOURCES}" -a "${LOGGING_SOURCES}" != "0" ] \
41 && src=" [${FUNCNAME[1]}()]"
43 [ -n "${LOGGING_DEBUG}" ] && [ "${LOGGING_DEBUG}" -ne 0 ] \
44 && printf "${fmt}" "DEBUG" "${@}" "${src}" 1>&2
46 for f in "${LOGGING_HOOKS_DEBUG[@]}" "${LOGGING_HOOKS_ALL[@]}"; do "${f}" "${@}" ; done
54 local fmt="$(_logging_fmt "${1}")"
59 [ -n "${LOGGING_SOURCES}" -a "${LOGGING_SOURCES}" != "0" ] \
60 && src=" [${FUNCNAME[1]}()]"
62 ( [ -z "${LOGGING_QUIET}" ] || [ "${LOGGING_QUIET}" -eq 0 ] ) \
63 && printf "${fmt}" "INFO" "${@}" "${src}"
65 for f in "${LOGGING_HOOKS_INFO[@]}" "${LOGGING_HOOKS_ALL[@]}"; do "${f}" "${@}" ; done
73 local fmt="$(_logging_fmt "${2}")"
75 local label="${1:-ERROR}"
79 [ -n "${LOGGING_SOURCES}" -a "${LOGGING_SOURCES}" != "0" ] \
80 && src=" [${FUNCNAME[2]}()]"
82 printf "${fmt}" "${label}" "${@}" "${src}" 1>&2
84 for f in $(eval "echo \"\${LOGGING_HOOKS_${label}[@]}\"") "${LOGGING_HOOKS_ALL[@]}" ; do "${f}" "${@}" ; done
89 _logging_log_err NOTICE "${@}"
94 _logging_log_err WARNING "${@}"
99 _logging_log_err ERROR "${@}"
104 _logging_log_err ALERT "${@}"
109 _logging_log_err EMERG "${@}"
114 _logging_log_err CRIT "${@}"
125 [ "${BASH_SOURCE}" != "${0}" ] || _main "${@}"