Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce logging verbosity #5

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/tinyramfs.8.scd
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ unlocking encrypted drives, mounting needed filesystems, etc.

Look for kernel modules in <path>, instead of /lib/modules/.

*-v*

Increase logging verbosity..

# FILES

/lib/tinyramfs/hook.d/
Expand Down
27 changes: 25 additions & 2 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ print()
printf "%s %s\n" "${2:-">>"}" "$1"
}

print_loglevel()
{
[ "$1" -gt "$loglevel" ] && return
prefix=""
case "$1" in
0) prefix="ERROR:" ;;
1) prefix="WARN:" ;;
2) prefix="INFO:" ;;
esac
print "$2" "$prefix"
unset prefix
}

print_warn()
{
print_loglevel 1 "$1"
}

print_verbose()
{
print_loglevel 2 "$1"
}

panic()
{
eval_hooks init.fail
Expand Down Expand Up @@ -108,7 +131,7 @@ copy_kmod()
[ "$modpath" = "name:" ] && return 0
[ "$modpath" = "(builtin)" ] && return 0
else
print "missing module: $1"
print_verbose "missing module: $1"
return
fi
[ -f "${tmpdir}/$modpath" ] && return
Expand All @@ -122,7 +145,7 @@ copy_kmod()
fi
done
if [ ! -f "/lib/firmware/$firmwarefile" ]; then
print "missing firmware for $modname: $line"
print_warn "missing firmware for $modname: $line"
else
copy_file "/lib/firmware/$firmwarefile"
fi
Expand Down
18 changes: 12 additions & 6 deletions tinyramfs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ usage: ${0##*/} [option]... <output>
-l enable local mode
-d enable debug mode
-f overwrite initramfs image
-v increase logging verbosity
-h display this message
EOF

Expand Down Expand Up @@ -177,15 +178,20 @@ create_image()
print "done: $output" '+>'
}

while getopts c:k:m:ldfh opt; do case $opt in
# 0: error
# 1: warning
# 2: info
loglevel=1
while getopts c:k:m:ldfvh opt; do case $opt in
c) config=$OPTARG ;;
k) kernel=$OPTARG ;;
m) moddir=$OPTARG ;;
l) local=1 ;;
d) debug=1 ;;
f) force=1 ;;
h) usage 0 ;;
?) usage 2 ;;
l) local=1 ;;
d) debug=1 ;;
f) force=1 ;;
v) loglevel=$((loglevel + 1)) ;;
h) usage 0 ;;
?) usage 2 ;;
esac; done

shift "$((OPTIND - 1))"
Expand Down
Loading