Skip to content
Snippets Groups Projects
Commit a74772e8 authored by Anthony's avatar Anthony
Browse files

Improve doli logs command

parent 1557a407
No related branches found
No related tags found
1 merge request!4Improve doli logs command
...@@ -31,7 +31,9 @@ usage() { ...@@ -31,7 +31,9 @@ usage() {
echo "help" echo "help"
echo -e "\t displays this messages and exit" echo -e "\t displays this messages and exit"
echo "logs" echo "logs"
echo -e "\t Follow all usefull logs" echo -e "\t Follow all useful logs"
echo "logs <term1> <term2> ..."
echo -e "\t Follow all useful logs and highlight terms"
echo "mysql" echo "mysql"
echo -e "\t pen a mysql prompt in LNB database" echo -e "\t pen a mysql prompt in LNB database"
echo "mysql_dump" echo "mysql_dump"
...@@ -96,7 +98,22 @@ case $action in ...@@ -96,7 +98,22 @@ case $action in
;; ;;
"logs") "logs")
set -x set -x
$cmd tail -f $document_path/dolibarr.log \ # All parameters after $1 are highlight terms
HIGHLIGHT_TERMS=("${@:1}")
# Build sed command: start with highlighting ERR in red
sed_exprs=( -e 's/ERR/\x1b[31m&\x1b[0m/g' )
# Add each additional highlight term in yellow background + black text
for term in "${HIGHLIGHT_TERMS[@]}"; do
# Escape slashes and ampersands
safe_term=$(printf '%s' "$term" | sed 's/[\/&]/\\&/g')
sed_exprs+=( -e "s/$safe_term/\x1b[4;43;97m&\x1b[0m/gI" )
done
# Pipe logs through constructed sed commands and reader
$cmd tail -f \
$document_path/dolibarr.log \
$document_path/dolibarr_payment.log \ $document_path/dolibarr_payment.log \
$document_path/dolibarr_cron.log \ $document_path/dolibarr_cron.log \
$document_path/cron_run_jobs.php.log \ $document_path/cron_run_jobs.php.log \
...@@ -104,7 +121,10 @@ case $action in ...@@ -104,7 +121,10 @@ case $action in
/var/log/apache2/access.log \ /var/log/apache2/access.log \
/var/log/apache2/dolibarr_access.log \ /var/log/apache2/dolibarr_access.log \
/var/log/apache2/dolibarr_error.log \ /var/log/apache2/dolibarr_error.log \
/var/log/apache2/dolibarr_erro..log | $reader /var/log/apache2/dolibarr_erro..log\
| LC_ALL=C sed "${sed_exprs[@]}" \
| $reader
set +x set +x
;; ;;
"mysql") "mysql")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment