Rewritten Log Handling

* Now you can set log_level to your needs.
See README.md for Details.
* Added Option to delete log file on restarts
* develop_log: true
*
* Updated README.md accordingly

Signed-off-by: Stephan Wendel <me@stephanwe.de>
This commit is contained in:
Stephan Wendel 2021-11-02 21:09:34 +01:00
parent 7e278cde4b
commit 6891584990
2 changed files with 78 additions and 17 deletions

View File

@ -121,11 +121,43 @@ This last 2 should be pretty obvious :)
There are two more existing parameters, There are two more existing parameters,
log_method: debug log_level:
**This parameter _has_ to reside under [webcamd] section!** **This parameter _has_ to reside under [webcamd] section!**
This forces webcamd to spit out more camera informations.\ You can choose:
log_level: quiet
This Option shows a bare minimum Logfile.\
For example:
[11/02/21 20:47:52] webcamd: webcamd - A webcam Service for multiple Cams and Stream Services.
[11/02/21 20:47:53] webcamd: Version: v0.1.3-9-g7e278cd
[11/02/21 20:47:53] webcamd: Prepare Startup ...
[11/02/21 20:47:53] webcamd: INFO: Checking Dependencys
[11/02/21 20:47:53] webcamd: Dependency: 'crudini' found in /usr/bin/crudini.
[11/02/21 20:47:53] webcamd: Dependency: 'mjpg_streamer' found in /usr/local/bin/mjpg_streamer.
[11/02/21 20:47:53] webcamd: Dependency: 'ustreamer' found in /usr/local/bin/ustreamer.
[11/02/21 20:47:53] webcamd: Dependency: 'v4l2rtspserver' found in /usr/local/bin/v4l2rtspserver.
[11/02/21 20:47:54] webcamd: INFO: Detect available Cameras
[11/02/21 20:47:54] webcamd: INFO: Found 2 available Camera(s)
[11/02/21 20:47:54] webcamd: /dev/v4l/by-id/usb-USB_Camera_USB_Camera_SN0001-video-index0 -> /dev/video1
[11/02/21 20:47:54] webcamd: Detected 'Raspicam' Device -> /dev/video0
[11/02/21 20:47:54] webcamd: Try to start configured Cams / Services...
[11/02/21 20:47:55] webcamd: INFO: Configuration of Section [cam 1] looks good. Continue...
[11/02/21 20:47:55] webcamd: Starting mjpeg-streamer with Device /dev/video0 ...
[11/02/21 20:48:03] webcamd: INFO: Configuration of Section [cam usb_black] looks good. Continue...
[11/02/21 20:48:04] webcamd: Starting ustreamer with Device /dev/v4l/by-id/usb-USB_Camera_USB_Camera_SN0001-video-index0 ...
[11/02/21 20:48:11] webcamd: ... Done!
The next option is
log_level: verbose
This gives you a little more Informations.
It prints out you existing webcam.conf and shows
a detailed info about your configured ( and connected ) cams.\
Like that: Like that:
[10/24/21 02:46:00] webcamd: INFO: Detect available Cameras [10/24/21 02:46:00] webcamd: INFO: Detect available Cameras
@ -163,8 +195,24 @@ Like that:
This is useful to determine what the Hardware Encoder of your Camera is capable of.\ This is useful to determine what the Hardware Encoder of your Camera is capable of.\
In this case a "cheap" raspicam for about 7€ was used.\ In this case a "cheap" raspicam for about 7€ was used.\
But it has a downside, everytime you restart webcamd, it will delete the Logfile! So, truly made for 'Helper for Setup' purposes.
So, truly made for Debugging purposes.
If you want to get the full Details, please use
log_level: debug
This will show you barely the same as 'verbose' but it prints also your\
configured Start Parameters ( and the defaults ), also it shows\
the Output of your choosen Streamer.\
This option ist more for debugging purposes and has a tendency to overwhelm you if you are not familiar with that.
---
Another Option that affects the 'logging' behavior is
develop_log: true
If you enable that option, everytime you restart, your existing log file will be deleted.
--- ---

39
webcamd
View File

@ -50,15 +50,28 @@ function init_log_entry {
log_msg "Prepare Startup ..." log_msg "Prepare Startup ..."
} }
function log_method { function log_level {
local method logfile local loglevel
logfile="$(get_param webcamd log_path | sed "s#^~#$HOME#gi")" loglevel="$(get_param webcamd log_level 2> /dev/null)"
method="$(get_param "webcamd" log_method 2> /dev/null)" # Set default log_level to quiet
if [ "${method}" = "debug" ]; then if [ -z "${loglevel}" ] || [[ "${loglevel}" != @(quiet|verbose|debug) ]];
then
echo "quiet"
else
echo "${loglevel}"
fi
}
function develop {
local devel logfile
logfile="$(get_param "webcamd" log_path | sed "s#^~#$HOME#gi")"
devel="$(get_param "webcamd" develop_log 2> /dev/null)"
if [ "${devel}" = "true" ]; then
rm -rf "${logfile}" rm -rf "${logfile}"
fi fi
} }
function log_msg { function log_msg {
local msg logfile prefix local msg logfile prefix
msg="${1}" msg="${1}"
@ -74,10 +87,9 @@ function log_msg {
#call '| log_output "<prefix>"' #call '| log_output "<prefix>"'
function log_output { function log_output {
local prefix debug local prefix
prefix="DEBUG: ${1}" prefix="DEBUG: ${1}"
debug="$(get_param "webcamd" debug_log 2> /dev/null)" if [ "$(log_level)" == "debug" ]; then
if [ "${debug}" == "true" ]; then
while read -r line; do while read -r line; do
log_msg "${prefix}: ${line}" log_msg "${prefix}: ${line}"
done done
@ -111,7 +123,7 @@ function print_cams {
raspicam="$(v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \ raspicam="$(v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
awk 'NR==2 {print $1}')" awk 'NR==2 {print $1}')"
log_msg "Detected 'Raspicam' Device -> ${raspicam}" log_msg "Detected 'Raspicam' Device -> ${raspicam}"
if [ "${debug}" == "true" ]; then if [ ! "$(log_level)" = "quiet" ]; then
list_cam_formats "${raspicam}" list_cam_formats "${raspicam}"
fi fi
fi fi
@ -124,9 +136,10 @@ function initial_check {
check_dep "mjpg_streamer" check_dep "mjpg_streamer"
check_dep "ustreamer" check_dep "ustreamer"
check_dep "v4l2rtspserver" check_dep "v4l2rtspserver"
log_msg "INFO: Checking Configfile"
if [ -z "$(check_cfg "${WEBCAMD_CFG}")" ]; then if [ -z "$(check_cfg "${WEBCAMD_CFG}")" ]; then
print_cfg if [ "$(log_level)" != "quiet" ]; then
print_cfg
fi
fi fi
log_msg "INFO: Detect available Cameras" log_msg "INFO: Detect available Cameras"
print_cams print_cams
@ -177,7 +190,7 @@ function detect_avail_cams {
echo "${avail}" | while read -r i; do echo "${avail}" | while read -r i; do
realpath=$(readlink -e ${i}) realpath=$(readlink -e ${i})
log_msg "${i} -> ${realpath}" log_msg "${i} -> ${realpath}"
if [ "${debug}" == "true" ]; then if [ "$(log_level)" != "quiet" ]; then
list_cam_formats "${i}" list_cam_formats "${i}"
fi fi
done done
@ -487,7 +500,7 @@ done
trap 'shutdown' 1 2 3 15 trap 'shutdown' 1 2 3 15
trap 'err_exit $? $LINENO' ERR trap 'err_exit $? $LINENO' ERR
log_method develop
init_log_entry init_log_entry
initial_check initial_check
construct_streamer construct_streamer