66 lines
1.7 KiB
Bash
66 lines
1.7 KiB
Bash
#!/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() {
|
|
|
|
# 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}'`
|
|
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
|
|
}
|