Skip to content

Commit

Permalink
Merge pull request #1057 from m-1-k-3/perl_scanning
Browse files Browse the repository at this point in the history
Improve module_title log
  • Loading branch information
m-1-k-3 committed Feb 29, 2024
2 parents e823b8f + e5b4951 commit 661b015
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions helpers/helpers_emba_print.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,28 @@ module_log_init()
fi
}

# $1: module title
# $2: (optional) log file to log -> this is typically used in combination with write_log to write
# logs to another log file
# no_log is also valid to just print to cli
module_title()
{
local MODULE_TITLE
MODULE_TITLE="${1:-}"
local MODULE_TITLE_FORMAT
MODULE_TITLE_FORMAT="[""${BLUE}""+""${NC}""] ""${CYAN}""${BOLD}""${MODULE_TITLE}""${NC}""\\n""${BOLD}""=================================================================""${NC}"
local MODULE_TITLE="${1:-}"
local LOG_FILE_TO_LOG="${2:-}"

if [[ "${LOG_FILE_TO_LOG:-}" != "no_log" ]] && ! [[ -f "${LOG_FILE_TO_LOG}" ]]; then
LOG_FILE_TO_LOG="${LOG_FILE}"
fi

local MODULE_TITLE_FORMAT="[""${BLUE}""+""${NC}""] ""${CYAN}""${BOLD}""${MODULE_TITLE}""${NC}""\\n""${BOLD}""=================================================================""${NC}"
echo -e "\\n\\n""${MODULE_TITLE_FORMAT}" || true
if [[ "${2:-}" != "no_log" ]] ; then
echo -e "$(format_log "${MODULE_TITLE_FORMAT}")" | tee -a "${LOG_FILE}" >/dev/null || true
if [[ ${LOG_GREP} -eq 1 ]] ; then
write_grep_log "${MODULE_TITLE}" "MODULE_TITLE"
fi

if [[ "${LOG_FILE_TO_LOG:-}" != "no_log" ]] ; then
echo -e "$(format_log "${MODULE_TITLE_FORMAT}")" | tee -a "${LOG_FILE_TO_LOG}" >/dev/null || true
fi

if [[ ${LOG_GREP} -eq 1 ]] ; then
write_grep_log "${MODULE_TITLE}" "MODULE_TITLE"
fi
SUB_MODULE_COUNT=0
}
Expand All @@ -98,15 +108,17 @@ sub_module_title()
local SUB_MODULE_TITLE="${1:-}"
local LOG_FILE_TO_LOG="${2:-}"
# if $2 is not set, we are going to log to the original LOG_FILE
if ! [[ -f "${LOG_FILE_TO_LOG}" ]]; then
if [[ "${LOG_FILE_TO_LOG:-}" != "no_log" ]] && ! [[ -f "${LOG_FILE_TO_LOG}" ]]; then
LOG_FILE_TO_LOG="${LOG_FILE}"
fi

local SUB_MODULE_TITLE_FORMAT=""

SUB_MODULE_TITLE_FORMAT="\\n""${BLUE}""==>""${NC}"" ""${CYAN}""${SUB_MODULE_TITLE}""${NC}""\\n-----------------------------------------------------------------"
echo -e "${SUB_MODULE_TITLE_FORMAT}" || true
echo -e "$(format_log "${SUB_MODULE_TITLE_FORMAT}")" | tee -a "${LOG_FILE_TO_LOG}" >/dev/null || true
if [[ "${LOG_FILE_TO_LOG:-}" != "no_log" ]] ; then
echo -e "$(format_log "${SUB_MODULE_TITLE_FORMAT}")" | tee -a "${LOG_FILE_TO_LOG}" >/dev/null || true
fi

if [[ ${LOG_GREP} -eq 1 ]] ; then
SUB_MODULE_COUNT=$((SUB_MODULE_COUNT + 1))
Expand Down

0 comments on commit 661b015

Please sign in to comment.