Remove unused log levels for kdump logger

Previously, the range of log level is from 1 to 6, and the TRACE
level and FATAL level are not used, therefore, let's remove these
unused log levels.

Now it has only four log levels: error(1), warn(2), info(3)
and debug(4). We have to remap the numeric log level to the logger
priority or syslog log level, which is finished in kdump-logger.sh
module, it is invisible for user.

Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
Acked-by: Kairui Song <kasong@redhat.com>
This commit is contained in:
Lianbo Jiang 2020-11-12 23:55:38 +08:00 committed by Kairui Song
parent 2dea15c4fd
commit 5b2b7ec08b
1 changed files with 42 additions and 105 deletions

View File

@ -2,24 +2,18 @@
# #
# This comes from the dracut-logger.sh # This comes from the dracut-logger.sh
# #
# The logger defined 6 logging levels: # The logger defined 4 logging levels:
# - dtrace() (6) # - ddebug (4)
# The TRACE Level designates finer-grained informational events than the
# DEBUG.
# - ddebug (5)
# The DEBUG Level designates fine-grained informational events that are most # The DEBUG Level designates fine-grained informational events that are most
# useful to debug an application. # useful to debug an application.
# - dinfo (4) # - dinfo (3)
# The INFO level designates informational messages that highlight the # The INFO level designates informational messages that highlight the
# progress of the application at coarse-grained level. # progress of the application at coarse-grained level.
# - dwarn (3) # - dwarn (2)
# The WARN level designates potentially harmful situations. # The WARN level designates potentially harmful situations.
# - derror (2) # - derror (1)
# The ERROR level designates error events that might still allow the # The ERROR level designates error events that might still allow the
# application to continue running. # application to continue running.
# - dfatal (1)
# The FATAL level designates very severe error events that will presumably
# lead the application to abort.
# #
# Logging is controlled by following global variables: # Logging is controlled by following global variables:
# - @var kdump_stdloglvl - logging level to standard error (console output) # - @var kdump_stdloglvl - logging level to standard error (console output)
@ -27,8 +21,8 @@
# - @var kdump_kmsgloglvl - logging level to /dev/kmsg (only for boot-time) # - @var kdump_kmsgloglvl - logging level to /dev/kmsg (only for boot-time)
# #
# If any of the variables is not set, this function set it to default: # If any of the variables is not set, this function set it to default:
# - @var kdump_stdloglvl = 4 (info) # - @var kdump_stdloglvl = 3 (info)
# - @var kdump_sysloglvl = 4 (info) # - @var kdump_sysloglvl = 3 (info)
# - @var kdump_kmsgloglvl = 0 (no logging) # - @var kdump_kmsgloglvl = 0 (no logging)
# #
# First of all you have to start with dlog_init() function which initializes # First of all you have to start with dlog_init() function which initializes
@ -42,7 +36,7 @@
check_loglvl() check_loglvl()
{ {
case "$1" in case "$1" in
0|1|2|3|4|5|6) 0|1|2|3|4)
return 0 return 0
;; ;;
*) *)
@ -58,8 +52,8 @@ check_loglvl()
dlog_init() { dlog_init() {
local ret=0; local errmsg local ret=0; local errmsg
[ -z "$kdump_stdloglvl" ] && kdump_stdloglvl=4 [ -z "$kdump_stdloglvl" ] && kdump_stdloglvl=3
[ -z "$kdump_sysloglvl" ] && kdump_sysloglvl=4 [ -z "$kdump_sysloglvl" ] && kdump_sysloglvl=3
[ -z "$kdump_kmsgloglvl" ] && kdump_kmsgloglvl=0 [ -z "$kdump_kmsgloglvl" ] && kdump_kmsgloglvl=0
for loglvl in "$kdump_stdloglvl" "$kdump_kmsgloglvl" "$kdump_sysloglvl"; do for loglvl in "$kdump_stdloglvl" "$kdump_kmsgloglvl" "$kdump_sysloglvl"; do
@ -103,83 +97,52 @@ dlog_init() {
readonly kdump_maxloglvl=$maxloglvl_l readonly kdump_maxloglvl=$maxloglvl_l
export kdump_maxloglvl export kdump_maxloglvl
if [[ $kdump_stdloglvl -lt 4 ]] && [[ $kdump_kmsgloglvl -lt 4 ]] && [[ $kdump_sysloglvl -lt 4 ]]; then
if [[ $kdump_stdloglvl -lt 6 ]] && [[ $kdump_kmsgloglvl -lt 6 ]] && [[ $kdump_sysloglvl -lt 6 ]]; then
unset dtrace
dtrace() { :; };
fi
if [[ $kdump_stdloglvl -lt 5 ]] && [[ $kdump_kmsgloglvl -lt 5 ]] && [[ $kdump_sysloglvl -lt 5 ]]; then
unset ddebug unset ddebug
ddebug() { :; }; ddebug() { :; };
fi fi
if [[ $kdump_stdloglvl -lt 4 ]] && [[ $kdump_kmsgloglvl -lt 4 ]] && [[ $kdump_sysloglvl -lt 4 ]]; then if [[ $kdump_stdloglvl -lt 3 ]] && [[ $kdump_kmsgloglvl -lt 3 ]] && [[ $kdump_sysloglvl -lt 3 ]]; then
unset dinfo unset dinfo
dinfo() { :; }; dinfo() { :; };
fi fi
if [[ $kdump_stdloglvl -lt 3 ]] && [[ $kdump_kmsgloglvl -lt 3 ]] && [[ $kdump_sysloglvl -lt 3 ]]; then if [[ $kdump_stdloglvl -lt 2 ]] && [[ $kdump_kmsgloglvl -lt 2 ]] && [[ $kdump_sysloglvl -lt 2 ]]; then
unset dwarn unset dwarn
dwarn() { :; }; dwarn() { :; };
unset dwarning unset dwarning
dwarning() { :; }; dwarning() { :; };
fi fi
if [[ $kdump_stdloglvl -lt 2 ]] && [[ $kdump_kmsgloglvl -lt 2 ]] && [[ $kdump_sysloglvl -lt 2 ]]; then if [[ $kdump_stdloglvl -lt 1 ]] && [[ $kdump_kmsgloglvl -lt 1 ]] && [[ $kdump_sysloglvl -lt 1 ]]; then
unset derror unset derror
derror() { :; }; derror() { :; };
fi fi
if [[ $kdump_stdloglvl -lt 1 ]] && [[ $kdump_kmsgloglvl -lt 1 ]] && [[ $kdump_sysloglvl -lt 1 ]]; then
unset dfatal
dfatal() { :; };
fi
[ -n "$errmsg" ] && derror "$errmsg" [ -n "$errmsg" ] && derror "$errmsg"
return $ret return $ret
} }
## @brief Converts numeric logging level to the first letter of level name.
#
# @param lvl Numeric logging level in range from 1 to 6.
# @retval 1 if @a lvl is out of range.
# @retval 0 if @a lvl is correct.
# @result Echoes first letter of level name.
_lvl2char() {
case "$1" in
1) echo F;;
2) echo E;;
3) echo W;;
4) echo I;;
5) echo D;;
6) echo T;;
*) return 1;;
esac
}
## @brief Converts numeric level to logger priority defined by POSIX.2. ## @brief Converts numeric level to logger priority defined by POSIX.2.
# #
# @param lvl Numeric logging level in range from 1 to 6. # @param lvl Numeric logging level in range from 1 to 4.
# @retval 1 if @a lvl is out of range. # @retval 1 if @a lvl is out of range.
# @retval 0 if @a lvl is correct. # @retval 0 if @a lvl is correct.
# @result Echoes logger priority. # @result Echoes logger priority.
_lvl2syspri() { _lvl2syspri() {
case "$1" in case "$1" in
1) echo crit;; 1) echo error;;
2) echo error;; 2) echo warning;;
3) echo warning;; 3) echo info;;
4) echo info;; 4) echo debug;;
5) echo debug;;
6) echo debug;;
*) return 1;; *) return 1;;
esac esac
} }
## @brief Converts logger numeric level to syslog log level ## @brief Converts logger numeric level to syslog log level
# #
# @param lvl Numeric logging level in range from 1 to 6. # @param lvl Numeric logging level in range from 1 to 4.
# @retval 1 if @a lvl is out of range. # @retval 1 if @a lvl is out of range.
# @retval 0 if @a lvl is correct. # @retval 0 if @a lvl is correct.
# @result Echoes kernel console numeric log level # @result Echoes kernel console numeric log level
@ -189,13 +152,12 @@ _lvl2syspri() {
# <tt> # <tt>
# none -> LOG_EMERG (0) # none -> LOG_EMERG (0)
# none -> LOG_ALERT (1) # none -> LOG_ALERT (1)
# FATAL(1) -> LOG_CRIT (2) # none -> LOG_CRIT (2)
# ERROR(2) -> LOG_ERR (3) # ERROR(1) -> LOG_ERR (3)
# WARN(3) -> LOG_WARNING (4) # WARN(2) -> LOG_WARNING (4)
# none -> LOG_NOTICE (5) # none -> LOG_NOTICE (5)
# INFO(4) -> LOG_INFO (6) # INFO(3) -> LOG_INFO (6)
# DEBUG(5) -> LOG_DEBUG (7) # DEBUG(4) -> LOG_DEBUG (7)
# TRACE(6) /
# </tt> # </tt>
# #
# @see /usr/include/sys/syslog.h # @see /usr/include/sys/syslog.h
@ -203,29 +165,27 @@ _dlvl2syslvl() {
local lvl local lvl
case "$1" in case "$1" in
1) lvl=2;; 1) lvl=3;;
2) lvl=3;; 2) lvl=4;;
3) lvl=4;; 3) lvl=6;;
4) lvl=6;; 4) lvl=7;;
5) lvl=7;;
6) lvl=7;;
*) return 1;; *) return 1;;
esac esac
[ -s /proc/vmcore ] && echo $((24+$lvl)) || echo $((8+$lvl)) [ -s /proc/vmcore ] && echo $((24+$lvl)) || echo $((8+$lvl))
} }
## @brief Prints to stderr and/or writes to file, to syslog and/or /dev/kmsg ## @brief Prints to stderr, to syslog and/or /dev/kmsg given message with
# given message with given level (priority). # given level (priority).
# #
# @param lvl Numeric logging level. # @param lvl Numeric logging level.
# @param msg Message. # @param msg Message.
# @retval 0 It's always returned, even if logging failed. # @retval 0 It's always returned, even if logging failed.
# #
# @note This function is not supposed to be called manually. Please use # @note This function is not supposed to be called manually. Please use
# dtrace(), ddebug(), or others instead which wrap this one. # dinfo(), ddebug(), or others instead which wrap this one.
# #
# This is core logging function which logs given message to standard error, file # This is core logging function which logs given message to standard error
# and/or syslog (with POSIX shell command <tt>logger</tt>) and/or to /dev/kmsg. # and/or syslog (with POSIX shell command <tt>logger</tt>) and/or to /dev/kmsg.
# The format is following: # The format is following:
# #
@ -236,16 +196,13 @@ _dlvl2syslvl() {
# #
# Message to syslog is sent with tag @c kdump. Priorities are mapped as # Message to syslog is sent with tag @c kdump. Priorities are mapped as
# following: # following:
# - @c FATAL to @c crit
# - @c ERROR to @c error # - @c ERROR to @c error
# - @c WARN to @c warning # - @c WARN to @c warning
# - @c INFO to @c info # - @c INFO to @c info
# - @c DEBUG and @c TRACE both to @c debug # - @c DEBUG to @c debug
_do_dlog() { _do_dlog() {
local lvl="$1"; shift local lvl="$1"; shift
local lvlc=$(_lvl2char "$lvl") || return 0
local msg="$*" local msg="$*"
local lmsg="$lvlc: $*"
[[ $lvl -le $kdump_stdloglvl ]] && printf -- 'kdump: %s\n' "$msg" >&2 [[ $lvl -le $kdump_stdloglvl ]] && printf -- 'kdump: %s\n' "$msg" >&2
@ -268,7 +225,7 @@ _do_dlog() {
# @retval 0 It's always returned, even if logging failed. # @retval 0 It's always returned, even if logging failed.
# #
# @note This function is not supposed to be called manually. Please use # @note This function is not supposed to be called manually. Please use
# dtrace(), ddebug(), or others instead which wrap this one. # dinfo(), ddebug(), or others instead which wrap this one.
# #
# This function calls _do_dlog() either with parameter msg, or if # This function calls _do_dlog() either with parameter msg, or if
# none is given, it will read standard input and will use every line as # none is given, it will read standard input and will use every line as
@ -290,43 +247,33 @@ dlog() {
fi fi
} }
## @brief Logs message at TRACE level (6) ## @brief Logs message at DEBUG level (4)
#
# @param msg Message.
# @retval 0 It's always returned, even if logging failed.
dtrace() {
set +x
dlog 6 "$@"
[ -n "$debug" ] && set -x || :
}
## @brief Logs message at DEBUG level (5)
# #
# @param msg Message. # @param msg Message.
# @retval 0 It's always returned, even if logging failed. # @retval 0 It's always returned, even if logging failed.
ddebug() { ddebug() {
set +x set +x
dlog 5 "$@" dlog 4 "$@"
[ -n "$debug" ] && set -x || : [ -n "$debug" ] && set -x || :
} }
## @brief Logs message at INFO level (4) ## @brief Logs message at INFO level (3)
# #
# @param msg Message. # @param msg Message.
# @retval 0 It's always returned, even if logging failed. # @retval 0 It's always returned, even if logging failed.
dinfo() { dinfo() {
set +x set +x
dlog 4 "$@" dlog 3 "$@"
[ -n "$debug" ] && set -x || : [ -n "$debug" ] && set -x || :
} }
## @brief Logs message at WARN level (3) ## @brief Logs message at WARN level (2)
# #
# @param msg Message. # @param msg Message.
# @retval 0 It's always returned, even if logging failed. # @retval 0 It's always returned, even if logging failed.
dwarn() { dwarn() {
set +x set +x
dlog 3 "$@" dlog 2 "$@"
[ -n "$debug" ] && set -x || : [ -n "$debug" ] && set -x || :
} }
@ -340,21 +287,11 @@ dwarning() {
[ -n "$debug" ] && set -x || : [ -n "$debug" ] && set -x || :
} }
## @brief Logs message at ERROR level (2) ## @brief Logs message at ERROR level (1)
# #
# @param msg Message. # @param msg Message.
# @retval 0 It's always returned, even if logging failed. # @retval 0 It's always returned, even if logging failed.
derror() { derror() {
set +x
dlog 2 "$@"
[ -n "$debug" ] && set -x || :
}
## @brief Logs message at FATAL level (1)
#
# @param msg Message.
# @retval 0 It's always returned, even if logging failed.
dfatal() {
set +x set +x
dlog 1 "$@" dlog 1 "$@"
[ -n "$debug" ] && set -x || : [ -n "$debug" ] && set -x || :