From a74772e8ba99563dc4fb2bc54411e65fc1b96502 Mon Sep 17 00:00:00 2001 From: Anthony Geourjon <anthony.geourjon@tetras-libre.fr> Date: Wed, 16 Apr 2025 16:18:02 +0200 Subject: [PATCH] Improve doli logs command --- doli | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/doli b/doli index 562de6b..b25f46b 100755 --- a/doli +++ b/doli @@ -30,8 +30,10 @@ usage() { echo -e "\t stops the docker stack" echo "help" echo -e "\t displays this messages and exit" - echo "logs" - echo -e "\t Follow all usefull logs" + echo "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 -e "\t pen a mysql prompt in LNB database" echo "mysql_dump" @@ -40,8 +42,8 @@ usage() { echo -e "\t populate LabNbook database (Docker only)" echo "mysql_restore" echo -e "\t restores database from a dump" - echo "perms" - echo -e "\t sets default files permissions" + echo "perms" + echo -e "\t sets default files permissions" echo "restart" echo -e "\t restart the docker stack or apache2" echo "shell" @@ -94,18 +96,36 @@ case $action in "help") usage ;; - "logs") - set -x - $cmd tail -f $document_path/dolibarr.log \ - $document_path/dolibarr_payment.log \ - $document_path/dolibarr_cron.log \ - $document_path/cron_run_jobs.php.log \ - $document_path/dolibarr.log \ - /var/log/apache2/access.log \ - /var/log/apache2/dolibarr_access.log \ - /var/log/apache2/dolibarr_error.log \ - /var/log/apache2/dolibarr_erro..log | $reader - set +x + "logs") + set -x + # 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_cron.log \ + $document_path/cron_run_jobs.php.log \ + $document_path/dolibarr.log \ + /var/log/apache2/access.log \ + /var/log/apache2/dolibarr_access.log \ + /var/log/apache2/dolibarr_error.log \ + /var/log/apache2/dolibarr_erro..log\ + | LC_ALL=C sed "${sed_exprs[@]}" \ + | $reader + + set +x ;; "mysql") set -x -- GitLab