logging: add verbose mode

Dumping commandline in debug mode
This commit is contained in:
2025-12-16 12:32:37 +08:00
parent f60ea1c5e5
commit 02e6a12063
3 changed files with 16 additions and 6 deletions

View File

@@ -41,7 +41,7 @@ generate_bsp() {
# Prepare pre-built rootfs
ROOTFS_DIR="$(mktemp -d)"
logi "Extracting pre-built rootfs to ${ROOTFS_DIR}"
logcmd tar -xvf "${ROOTFS_ARCHIVE}" -C "${ROOTFS_DIR}"
logcmd tar -x"$(log_expand_if_verbose "v")"f "${ROOTFS_ARCHIVE}" -C "${ROOTFS_DIR}"
setup_repo

View File

@@ -77,7 +77,7 @@ create_fs_mountpoint_content() {
prepare_fs_blocks
# Restore plain rootfs onto structured mountpoint
logi "Copy files"
logcmd rsync -avh "${ROOTFS_DIR}/" "${ROOTFS_MNT}"
logcmd rsync -a"$(log_expand_if_verbose "v")"h "${ROOTFS_DIR}/" "${ROOTFS_MNT}"
# Umount and shrink (if necessary)
post_fs_blocks

View File

@@ -1,13 +1,16 @@
#!/usr/bin/env false
readonly LOGLEVEL_DEBUG=0
readonly LOGLEVEL_INFO=1
readonly LOGLEVEL_WARN=2
readonly LOGLEVEL_ERROR=3
readonly LOGLEVEL_VERBOSE=0
readonly LOGLEVEL_DEBUG=1
readonly LOGLEVEL_INFO=2
readonly LOGLEVEL_WARN=3
readonly LOGLEVEL_ERROR=4
__logparselevel() {
if [ -z "${LOG_LEVEL:-}" ]; then
echo $LOGLEVEL_INFO
elif [ "${LOG_LEVEL}" = "VERBOSE" ]; then
echo $LOGLEVEL_VERBOSE
elif [ "${LOG_LEVEL}" = "DEBUG" ]; then
echo $LOGLEVEL_DEBUG
elif [ "${LOG_LEVEL}" = "INFO" ]; then
@@ -37,12 +40,19 @@ __logprint() {
logcmd() {
if [ "$(__logparselevel)" -le "$LOGLEVEL_DEBUG" ]; then
echo "+ $*"
{ "$@" ;}
else
{ "$@" >/dev/null 2>&1;}
fi
}
log_expand_if_verbose() {
if [ "$(__logparselevel)" -le "$LOGLEVEL_VERBOSE" ]; then
printf "%s" "$1"
fi
}
logd() {
if [ "$(__logparselevel)" -le "$LOGLEVEL_DEBUG" ]; then
__logprint "[DEBUG]" "$1"