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

81 lines
2.0 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
#-----------------------------------------------------------------------
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' \
"`date +%F' ~ '%T`" \
"$1" \
"$2" \
"$3" \
"$4" \
"$5" \
>> "$gsl_file_logs"
}
#-----------------------------------------------------------------------
# Show logs from file with filters
#-----------------------------------------------------------------------
gsl__logs_show() {
clear
# 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"
[[ "$gsl_logs_last_session" ]] \
&& gsl_log_show_session="Last session" \
|| gsl_log_show_session="All"
gsl_logs_infos=`
printf '%s\n%s\n%s\n' \
"Logs : $gsl_log_show_session" \
"Filter: $gsl_logs_filter" \
"Search: $gsl_logs_search"`
# 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}'`
printf '%s\n \n' "$gsl_logs_infos"
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
printf '%s\n' "$gsl_logs_infos"
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
}