2022-07-20 19:37:21 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# Name: Statique Littérateur
|
|
|
|
# Type: Logs Manager
|
|
|
|
# file: manage_logs
|
|
|
|
# Folder: /var/lib/stl/scripts/
|
|
|
|
# By echolib (XMPP: im@echolib.re)
|
|
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
2022-08-23 16:48:33 +02:00
|
|
|
#------------
|
|
|
|
# funny stats
|
|
|
|
#------------
|
|
|
|
# lines: 156
|
|
|
|
# functions: 3
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#**********************************************************************
|
2022-07-20 19:37:21 +02:00
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Manage Arguments
|
|
|
|
#======================================================================
|
|
|
|
log__OPTIONS() {
|
|
|
|
! [[ "$2" ]] && article_log="stl.log"
|
|
|
|
|
|
|
|
while test "$2"
|
|
|
|
do
|
2022-08-23 16:48:33 +02:00
|
|
|
case "$2" in
|
|
|
|
*.log)
|
|
|
|
article_log=`basename "$2"`
|
|
|
|
;;
|
|
|
|
|
|
|
|
*".stl")
|
|
|
|
unset article_log
|
|
|
|
article__hash "$2"
|
|
|
|
;;
|
|
|
|
|
|
|
|
clean)
|
|
|
|
log_clean=true
|
|
|
|
[[ $from_stl || $from_id ]] || article_log="stl.log"
|
|
|
|
;;
|
|
|
|
|
|
|
|
all)
|
|
|
|
[[ $log_clean ]] || continue
|
|
|
|
unset articl_log
|
|
|
|
rm -f /var/log/stl/*.log 2>/dev/null
|
|
|
|
echo "# All logs cleaned"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
noarg "$2" "Use: (ARTICLE) (+ clean)"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2022-07-20 19:37:21 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
! [[ -f "$stl_dir_log/$article_log" ]] \
|
2022-08-23 16:48:33 +02:00
|
|
|
&& echo "# No logs yet, for this article" \
|
2022-07-20 19:37:21 +02:00
|
|
|
&& exit
|
|
|
|
|
|
|
|
if [[ $log_clean ]];then
|
|
|
|
rm -f "$stl_dir_log/$article_log" && \
|
2022-08-23 16:48:33 +02:00
|
|
|
echo "# Logs cleaned: $stl_dir_log/$article_log"
|
|
|
|
exit
|
2022-07-20 19:37:21 +02:00
|
|
|
|
|
|
|
else
|
|
|
|
logs__print "$stl_dir_log/$article_log"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Add to log file $stl_file_log
|
|
|
|
#======================================================================
|
|
|
|
log__add() {
|
|
|
|
case "$1" in
|
|
|
|
-i) log_f1="$stl_log_i";CL=${NC} ;;
|
|
|
|
-w) log_f1="$stl_log_w";CL=${CY};stl_waring=true ;;
|
|
|
|
-e) log_f1="$stl_log_e";CL=${CR};stl_error=true ;;
|
|
|
|
*) log_f1="$1" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "$2" in
|
|
|
|
-C) log_f2="Check" ;;
|
|
|
|
-M) log_f2="WIP" ;;
|
2022-07-21 16:42:49 +02:00
|
|
|
-W) log_f2="WWW" ;;
|
2022-07-20 19:37:21 +02:00
|
|
|
-S) log_f2="Sidebar" ;;
|
|
|
|
-db) log_f2="Database" ;;
|
|
|
|
*) log_f2="$2"
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "$3" in
|
|
|
|
-Mti) log_f3="title:" ;;
|
|
|
|
-Mab) log_f3="about:" ;;
|
|
|
|
-Mau) log_f3="author:" ;;
|
|
|
|
-Mta) log_f3="tags:" ;;
|
|
|
|
-Mim) log_f3="image:" ;;
|
|
|
|
-Mda) log_f3="date:" ;;
|
|
|
|
-Mbr) log_f3="brut:" ;;
|
|
|
|
-Mpc) log_f3="code:" ;;
|
|
|
|
-Mlf) log_f3="file:" ;;
|
|
|
|
-Mlt) log_f3="link:" ;;
|
|
|
|
-M) log_f3="Metas" ;;
|
|
|
|
-A) log_f3="Article" ;;
|
2022-07-21 18:40:21 +02:00
|
|
|
-S) log_f3="Stats" ;;
|
2022-08-23 16:48:33 +02:00
|
|
|
-rs) log_f3="Publish" ;;
|
|
|
|
-rm) log_f3="Remove" ;;
|
|
|
|
-W) log_f3="Write" ;;
|
2022-07-20 19:37:21 +02:00
|
|
|
*) log_f3="$3"
|
|
|
|
esac
|
|
|
|
|
2022-08-23 16:48:33 +02:00
|
|
|
log_f4="$4"
|
|
|
|
|
|
|
|
# Maube to consider later...
|
|
|
|
#f4_l=${#log_f4}
|
|
|
|
#log_sp=$(( 40 - f4_l ))
|
|
|
|
#echo "> f4_l=$f4_l ; log_sp=$log_sp"
|
|
|
|
|
|
|
|
printf "%b%s%s%s%s%s%s%s%b\n" \
|
2022-07-20 19:37:21 +02:00
|
|
|
"${CL}" \
|
2022-08-23 16:48:33 +02:00
|
|
|
"`date +%F' '%T`│" \
|
|
|
|
"$domain_name│" \
|
|
|
|
"$log_f1│" \
|
|
|
|
"$log_f2│" \
|
|
|
|
"$log_f3│" \
|
|
|
|
"$log_f4│" \
|
|
|
|
"$this_article│" \
|
2022-07-20 19:37:21 +02:00
|
|
|
"${NC}" \
|
|
|
|
>> "$stl_file_last_log"
|
2022-08-23 16:48:33 +02:00
|
|
|
|
|
|
|
printf "%b%s%s%s%s%s%s%s%b\n" \
|
|
|
|
"${CL}" \
|
|
|
|
"`date +%F' '%T`│" \
|
|
|
|
"$domain_name│" \
|
|
|
|
"$log_f1│" \
|
|
|
|
"$log_f2│" \
|
|
|
|
"$log_f3│" \
|
|
|
|
"$log_f4│" \
|
|
|
|
"$this_article│" \
|
|
|
|
"${NC}" \
|
|
|
|
>> "$stl_dir_log/$article_id.log"
|
|
|
|
|
|
|
|
# Restore var
|
|
|
|
this_article="$this_article_bkp"
|
2022-07-20 19:37:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Show logs by column
|
|
|
|
# $1: file
|
|
|
|
#======================================================================
|
|
|
|
logs__print() {
|
2022-08-23 16:48:33 +02:00
|
|
|
[[ -f "$1" ]] || exit 0
|
|
|
|
|
|
|
|
cat "$1" | column -t -s'│' -o' '
|
|
|
|
|
|
|
|
#cat "$1" | column -t -s$'\t' -o' '
|
2022-07-20 19:37:21 +02:00
|
|
|
}
|