Skip to content

Commit ae88e02

Browse files
aafeijoo-suseLaszloGombos
authored andcommitted
feat(dracut): use log level indicator in console output
Also, use the same format in messages printed to console before dracut-logger is sourced. Fixes issue #1065
1 parent df381b7 commit ae88e02

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

dracut-logger.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ _do_dlog() {
323323
local msg="$*"
324324
local lmsg="$lvlc: $*"
325325

326-
((lvl <= stdloglvl)) && printf -- 'dracut: %s\n' "$msg" >&2
326+
((lvl <= stdloglvl)) && printf -- 'dracut[%s]: %s\n' "$lvlc" "$msg" >&2
327327

328328
if ((lvl <= sysloglvl)); then
329329
if [[ "$_dlogfd" ]]; then

dracut.sh

+27-27
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ unset GZIP
2525

2626
# Verify bash version, current minimum is 4
2727
if ((BASH_VERSINFO[0] < 4)); then
28-
printf -- 'You need at least Bash 4 to use dracut, sorry.' >&2
28+
printf "%s\n" "dracut[F]: dracut requires at least Bash 4." >&2
2929
exit 1
3030
fi
3131

@@ -326,8 +326,8 @@ read_arg() {
326326

327327
check_conf_file() {
328328
if grep -H -e '^[^#]*[+]=\("[^ ]\|.*[^ ]"\)' "$@"; then
329-
printf '\ndracut: WARNING: <key>+=" <values> ": <values> should have surrounding white spaces!\n' >&2
330-
printf 'dracut: WARNING: This will lead to unwanted side effects! Please fix the configuration file.\n\n' >&2
329+
printf '\ndracut[W]: <key>+=" <values> ": <values> should have surrounding white spaces!\n' >&2
330+
printf 'dracut[W]: This will lead to unwanted side effects! Please fix the configuration file.\n\n' >&2
331331
fi
332332
}
333333

@@ -907,7 +907,7 @@ if [[ -z $conffile ]]; then
907907
conffile="$dracutsysrootdir/etc/dracut.conf"
908908
fi
909909
elif [[ ! -e $conffile ]]; then
910-
printf "%s\n" "dracut: Configuration file '$conffile' not found." >&2
910+
printf "%s\n" "dracut[F]: Configuration file '$conffile' not found." >&2
911911
exit 1
912912
fi
913913

@@ -918,7 +918,7 @@ if [[ -z $confdir ]]; then
918918
confdir="$dracutsysrootdir/etc/dracut.conf.d"
919919
fi
920920
elif [[ ! -d $confdir ]]; then
921-
printf "%s\n" "dracut: Configuration directory '$confdir' not found." >&2
921+
printf "%s\n" "dracut[F]: Configuration directory '$confdir' not found." >&2
922922
exit 1
923923
fi
924924

@@ -945,12 +945,12 @@ fi
945945
if [[ $regenerate_all == "yes" ]]; then
946946
ret=0
947947
if [[ $kernel ]]; then
948-
printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
948+
printf "%s\n" "dracut[F]: --regenerate-all cannot be called with a kernel version." >&2
949949
exit 1
950950
fi
951951

952952
if [[ $outfile ]]; then
953-
printf -- "--regenerate-all cannot be called with a image file\n" >&2
953+
printf "%s\n" "dracut[F]: --regenerate-all cannot be called with an image file." >&2
954954
exit 1
955955
fi
956956

@@ -1097,12 +1097,12 @@ if ! [[ $outfile ]]; then
10971097
if [[ $uefi == "yes" ]]; then
10981098
# shellcheck disable=SC2154
10991099
if [[ -n $uefi_secureboot_key && -z $uefi_secureboot_cert ]] || [[ -z $uefi_secureboot_key && -n $uefi_secureboot_cert ]]; then
1100-
printf "%s\n" "dracut: Need 'uefi_secureboot_key' and 'uefi_secureboot_cert' both to be set." >&2
1100+
printf "%s\n" "dracut[F]: Need 'uefi_secureboot_key' and 'uefi_secureboot_cert' both to be set." >&2
11011101
exit 1
11021102
fi
11031103

11041104
if [[ -n $uefi_secureboot_key && -n $uefi_secureboot_cert ]] && ! command -v sbsign &> /dev/null; then
1105-
printf "%s\n" "dracut: Need 'sbsign' to create a signed UEFI executable." >&2
1105+
printf "%s\n" "dracut[F]: Need 'sbsign' to create a signed UEFI executable." >&2
11061106
exit 1
11071107
fi
11081108

@@ -1166,7 +1166,7 @@ fw_dir=${fw_dir//:/ }
11661166
if [[ -n $logfile ]]; then
11671167
if [[ ! -f $logfile ]]; then
11681168
if touch "$logfile"; then
1169-
printf "%s\n" "dracut: touch $logfile failed." >&2
1169+
printf "%s\n" "dracut[W]: touch $logfile failed." >&2
11701170
fi
11711171
fi
11721172
fi
@@ -1200,7 +1200,7 @@ case $hostonly_mode in
12001200
fi
12011201
;;
12021202
*)
1203-
printf "%s\n" "dracut: Invalid hostonly mode '$hostonly_mode'." >&2
1203+
printf "%s\n" "dracut[F]: Invalid hostonly mode '$hostonly_mode'." >&2
12041204
exit 1
12051205
;;
12061206
esac
@@ -1210,39 +1210,39 @@ esac
12101210
if [[ -z $DRACUT_KMODDIR_OVERRIDE && -n $drivers_dir ]]; then
12111211
drivers_basename="${drivers_dir##*/}"
12121212
if [[ -n $drivers_basename && $drivers_basename != "$kernel" ]]; then
1213-
printf "%s\n" "dracut: The provided directory where to look for kernel modules ($drivers_basename)" >&2
1214-
printf "%s\n" "dracut: does not match the kernel version set for the initramfs ($kernel)." >&2
1215-
printf "%s\n" "dracut: Set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check." >&2
1213+
printf "%s\n" "dracut[F]: The provided directory where to look for kernel modules ($drivers_basename)" >&2
1214+
printf "%s\n" "dracut[F]: does not match the kernel version set for the initramfs ($kernel)." >&2
1215+
printf "%s\n" "dracut[F]: Set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check." >&2
12161216
exit 1
12171217
fi
12181218
drivers_dirname="${drivers_dir%/*}/"
12191219
if [[ ! $drivers_dirname =~ .*/lib/modules/$ ]]; then
1220-
printf "%s\n" "dracut: drivers_dir path ${drivers_dir_l:+"set via -k/--kmoddir "}must contain \"/lib/modules/\" as a parent of your kernel module directory," >&2
1221-
printf "%s\n" "dracut: or modules may not be placed in the correct location inside the initramfs." >&2
1222-
printf "%s\n" "dracut: was given: ${drivers_dir}" >&2
1223-
printf "%s\n" "dracut: expected: ${drivers_dirname}lib/modules/${kernel}" >&2
1224-
printf "%s\n" "dracut: Please move your modules into the correct directory structure and pass the new location," >&2
1225-
printf "%s\n" "dracut: or set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check." >&2
1220+
printf "%s\n" "dracut[F]: drivers_dir path ${drivers_dir_l:+"set via -k/--kmoddir "}must contain \"/lib/modules/\" as a parent of your kernel module directory," >&2
1221+
printf "%s\n" "dracut[F]: or modules may not be placed in the correct location inside the initramfs." >&2
1222+
printf "%s\n" "dracut[F]: was given: ${drivers_dir}" >&2
1223+
printf "%s\n" "dracut[F]: expected: ${drivers_dirname}lib/modules/${kernel}" >&2
1224+
printf "%s\n" "dracut[F]: Please move your modules into the correct directory structure and pass the new location," >&2
1225+
printf "%s\n" "dracut[F]: or set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check." >&2
12261226
exit 1
12271227
fi
12281228
fi
12291229
12301230
# shellcheck disable=SC2155
12311231
readonly TMPDIR="$(realpath -e "$tmpdir")"
12321232
[ -d "$TMPDIR" ] || {
1233-
printf "%s\n" "dracut: Invalid tmpdir '$tmpdir'." >&2
1233+
printf "%s\n" "dracut[F]: Invalid tmpdir '$tmpdir'." >&2
12341234
exit 1
12351235
}
12361236
12371237
if findmnt --raw -n --target "$tmpdir" --output=options | grep -q noexec; then
1238-
[[ $debug == yes ]] && printf "%s\n" "dracut: Tmpdir '$tmpdir' is mounted with 'noexec'."
1238+
[[ $debug == yes ]] && printf "%s\n" "dracut[D]: Tmpdir '$tmpdir' is mounted with 'noexec'." >&2
12391239
noexec=1
12401240
fi
12411241
12421242
# shellcheck disable=SC2155
12431243
readonly DRACUT_TMPDIR="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
12441244
[ -d "$DRACUT_TMPDIR" ] || {
1245-
printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
1245+
printf "%s\n" "dracut[F]: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
12461246
exit 1
12471247
}
12481248
@@ -1289,17 +1289,17 @@ fi
12891289
if systemd-detect-virt -c &> /dev/null; then
12901290
export DRACUT_NO_MKNOD=1 DRACUT_NO_XATTR=1
12911291
if [[ $hostonly ]]; then
1292-
printf "%s\n" "dracut: WARNING: running in hostonly mode in a container!!"
1292+
printf "%s\n" "dracut[W]: Running in hostonly mode in a container!" >&2
12931293
fi
12941294
fi
12951295
12961296
if [[ -f $dracutbasedir/dracut-init.sh ]]; then
12971297
# shellcheck source=./dracut-init.sh
12981298
. "$dracutbasedir"/dracut-init.sh
12991299
else
1300-
printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
1301-
printf "%s\n" "dracut: Are you running from a git checkout?" >&2
1302-
printf "%s\n" "dracut: Try passing -l as an argument to $dracut_cmd" >&2
1300+
printf "%s\n" "dracut[F]: Cannot find $dracutbasedir/dracut-init.sh." >&2
1301+
printf "%s\n" "dracut[F]: Are you running from a git checkout?" >&2
1302+
printf "%s\n" "dracut[F]: Try passing -l as an argument to $dracut_cmd" >&2
13031303
exit 1
13041304
fi
13051305

0 commit comments

Comments
 (0)