From e2a9fb104b71c7bbee04da5613af7b9895061414 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 2 Apr 2024 16:49:04 +0800 Subject: [PATCH 1/3] Script Refactoring --- scripts-new/lib/logging.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts-new/lib/logging.sh b/scripts-new/lib/logging.sh index 642ed1395..67864f706 100644 --- a/scripts-new/lib/logging.sh +++ b/scripts-new/lib/logging.sh @@ -262,8 +262,17 @@ function openim::log::print_blue() { function openim::log::print_red() { local current_time=$(date "+%Y-%m-%d %H:%M:%S %Z") - echo -e "[$current_time]" - echo -e "\033[0;31m$1\033[0m" + local msg_length=${#1} + local time_length=${#current_time} + local term_width=$(tput cols) + + local total_length=$((time_length + msg_length + 2)) + + if [ $total_length -gt $term_width ]; then + echo -e "[$current_time]\n\033[0;31m$1\033[0m" + else + echo -e "[$current_time] \033[0;31m$1\033[0m" + fi } From f3f2c6a94866580f6799678f12d6a4ad090e4c4b Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 2 Apr 2024 16:50:05 +0800 Subject: [PATCH 2/3] Script Refactoring --- scripts-new/lib/logging.sh | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/scripts-new/lib/logging.sh b/scripts-new/lib/logging.sh index 67864f706..642ed1395 100644 --- a/scripts-new/lib/logging.sh +++ b/scripts-new/lib/logging.sh @@ -262,17 +262,8 @@ function openim::log::print_blue() { function openim::log::print_red() { local current_time=$(date "+%Y-%m-%d %H:%M:%S %Z") - local msg_length=${#1} - local time_length=${#current_time} - local term_width=$(tput cols) - - local total_length=$((time_length + msg_length + 2)) - - if [ $total_length -gt $term_width ]; then - echo -e "[$current_time]\n\033[0;31m$1\033[0m" - else - echo -e "[$current_time] \033[0;31m$1\033[0m" - fi + echo -e "[$current_time]" + echo -e "\033[0;31m$1\033[0m" } From 6639601155472b0456b1827df7f5c8d2da4327ac Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 2 Apr 2024 16:54:02 +0800 Subject: [PATCH 3/3] Script Refactoring --- scripts-new/lib/logging.sh | 15 ++++++++++++--- scripts-new/start.sh | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts-new/lib/logging.sh b/scripts-new/lib/logging.sh index 642ed1395..19c78c768 100644 --- a/scripts-new/lib/logging.sh +++ b/scripts-new/lib/logging.sh @@ -254,21 +254,30 @@ function openim::log::test_log() { # openim::log::test_log -function openim::log::print_blue() { + +function openim::log::print_blue_two_line() { local current_time=$(date "+%Y-%m-%d %H:%M:%S %Z") echo -e "[$current_time]" echo -e "\033[0;34m$1\033[0m" } +function openim::log::print_blue() { + local current_time=$(date "+%Y-%m-%d %H:%M:%S %Z") + echo -e "[$current_time] \033[0;34m$1\033[0m" +} + + + + function openim::log::print_red() { local current_time=$(date "+%Y-%m-%d %H:%M:%S %Z") - echo -e "[$current_time]" - echo -e "\033[0;31m$1\033[0m" + echo -e "[$current_time] \033[0;31m$1\033[0m" } + openim::log::colorless() { local V="${V:-0}" if [[ ${OPENIM_VERBOSE} < ${V} ]]; then diff --git a/scripts-new/start.sh b/scripts-new/start.sh index f8a24ad01..8ba1be2bf 100644 --- a/scripts-new/start.sh +++ b/scripts-new/start.sh @@ -27,7 +27,7 @@ fi # Call the main function result=$(start_binaries) -openim::log::print_blue "$result" +openim::log::print_blue_two_line "$result" $OPENIM_SCRIPTS/check.sh