FEATURE: Added loggin to systemd

* webcamd logs now also to systemd.
* viewable via journalctl and systemctl status webcamd.
* Logs always in debug Style to systemd

Signed-off-by: Stephan Wendel <me@stephanwe.de>
This commit is contained in:
Stephan Wendel 2021-11-04 19:15:08 +01:00
parent ac2927e6b1
commit 9ef05e586a
2 changed files with 13 additions and 5 deletions

View File

@ -39,7 +39,7 @@ sudo rm -rf /var/log/webcamd.log
# Install Dependency
sudo apt update
sudo apt install crudini -y
sudo apt install crudini logger -y
# Install Project "crowsnest"
echo -e "Installing webcamd and enable Service"

16
webcamd
View File

@ -83,17 +83,22 @@ function log_msg {
mkdir -p "$(dirname "${logfile}")"
fi
echo -e "${prefix} ${msg}" | tr -s ' ' >> "${logfile}" 2>&1
echo -e "${msg}" | logger -t webcamd
}
#call '| log_output "<prefix>"'
function log_output {
local prefix
prefix="DEBUG: ${1}"
if [ "$(log_level)" == "debug" ]; then
while read -r line; do
while read -r line; do
if [ "$(log_level)" == "debug" ]; then
log_msg "${prefix}: ${line}"
done
fi
fi
if [ -n "${line}" ]; then
# sed is needed to prettify ustreamers output
logger -t webcamd "$(echo ${line} | sed 's/^--/ustreamer/')"
fi
done
}
function print_cfg {
@ -132,6 +137,7 @@ function print_cams {
## Sanity Checks
function initial_check {
log_msg "INFO: Checking Dependencys"
check_dep "logger"
check_dep "crudini"
check_dep "mjpg_streamer"
check_dep "ustreamer"
@ -141,6 +147,8 @@ function initial_check {
print_cfg
fi
fi
# in systemd show always config file
logger -t webcamd -f "${WEBCAMD_CFG}"
log_msg "INFO: Detect available Cameras"
print_cams
}