gsl-statique-litterateur/var/lib/gsl/scripts/gsl__log_manager

74 lines
1.8 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# file: gsl__log_manager
# Folder: /var/lib/gsl/scripts
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#-----------------------------------------------------------------------
# Print in log file
#-----------------------------------------------------------------------
2022-03-27 18:46:48 +02:00
gsl__logs_check() {
[[ "$gsl_checker_war" ]] \
&& echo && gsl log -s -w
[[ "$gsl_checker_err" ]] \
&& echo && gsl log -s -e
}
gsl__logs_print() {
#1: Level
#2: Type
#3: Process
#4: Infos
#5: File
printf '%s %s\t%s\t%s\t%s\t%s\n' \
2022-02-15 12:42:54 +01:00
"`date +%F' '%T`" \
"$1" \
"$2" \
"$3" \
"$4" \
"$5" \
>> "$gsl_file_logs"
}
#-----------------------------------------------------------------------
# Show logs from file with filters
#-----------------------------------------------------------------------
gsl__logs_show() {
# Choices are important, but let's give priority
[[ "$gsl_logs_inf" ]] \
&& gsl_logs_filter="$gsl_log_i"
[[ "$gsl_logs_war" ]] \
&& gsl_logs_filter="$gsl_log_w"
[[ "$gsl_logs_err" ]] \
&& gsl_logs_filter="$gsl_log_e"
# Last session show or not
if [[ "$gsl_logs_last_session" ]];then
gsl_log_start_line=`
grep -n "Starting" "$gsl_file_logs" \
| tail -1 \
| awk -F: '{print $1}'`
2022-03-27 18:46:48 +02:00
# echo
awk -v sl="$gsl_log_start_line" \
'NR >= sl' \
"$gsl_file_logs" \
| grep "$gsl_logs_filter" \
| grep -Ei "$gsl_logs_search" \
| column -t -s$'\t'
else
while read -r "gsl_log_content"
do
# Let's read clear sessions
[[ "$gsl_log_content" =~ "Starting" ]] \
&& echo
echo "$gsl_log_content"
done < <(cat "$gsl_file_logs" \
| grep "$gsl_logs_filter" \
| grep -Ei "$gsl_logs_search" \
| column -t -s$'\t')
fi
}