stl-statilque-litterateur/var/lib/stl/scripts/manage__logs

113 lines
2.4 KiB
Plaintext
Raw Normal View History

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
#======================================================================
# Manage Arguments
#======================================================================
log__OPTIONS() {
! [[ "$2" ]] && article_log="stl.log"
while test "$2"
do
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"
;;
*)
noarg "$2"
;;
esac
shift
done
! [[ -f "$stl_dir_log/$article_log" ]] \
&& echo "# Logs not found: $stl_dir_log/$article_log" \
&& exit
if [[ $log_clean ]];then
rm -f "$stl_dir_log/$article_log" && \
echo "# logs cleaned: $stl_dir_log/$article_log"
else
logs__print "$stl_dir_log/$article_log"
fi
exit
}
#======================================================================
# 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" ;;
*) log_f3="$3"
esac
printf '%b%s %s %-10s\t%-10s\t%-30s\t%s\t%s%b\n' \
"${CL}" \
"`date +%F' '%T`" \
"$log_f1" \
"$log_f2" \
"$log_f3" \
"$4" \
"$domain_name" \
"$this_article" \
"${NC}" \
>> "$stl_file_last_log"
}
#======================================================================
# Show logs by column
# $1: file
#======================================================================
logs__print() {
[[ -f "$1" ]] \
&& cat "$1" | column -t -s$'\t' -o' ' \
|| exit
}