mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
armbian-oleg: better logs; only include non-empty .log files
This commit is contained in:
@@ -387,7 +387,7 @@ function write_config_summary_output_file() {
|
||||
debug_src_temp_perms="$(getfacl -p "${SRC}"/.tmp 2> /dev/null)"
|
||||
|
||||
display_alert "Writing build config summary to" "debug log" "debug"
|
||||
LOG_ASSET="build.summary.txt" do_with_log_asset run_host_command_logged cat <<- EOF
|
||||
LOG_ASSET="build.summary.txt" do_with_log_asset cat <<- EOF
|
||||
## BUILD SCRIPT ENVIRONMENT
|
||||
|
||||
Repository: $REPOSITORY_URL
|
||||
|
||||
@@ -6,10 +6,10 @@ function display_alert() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
declare message="${1}" level="${3}" # params
|
||||
declare level_indicator="" inline_logs_color="" extra="" ci_log="" # this log
|
||||
declare -i skip_screen=0 # setting to 1 will not write to screen
|
||||
declare -i skip_logfile=0 # setting to 1 will not write to logfile
|
||||
declare message="${1}" level="${3}" # params
|
||||
declare level_indicator="" inline_logs_color="" extra="" extra_file="" ci_log="" # this log
|
||||
declare -i skip_screen=0 # setting to 1 will not write to screen
|
||||
declare -i skip_logfile=0 # setting to 1 will not write to logfile
|
||||
case "${level}" in
|
||||
err | error)
|
||||
level_indicator="💥"
|
||||
@@ -78,7 +78,7 @@ function display_alert() {
|
||||
skip_screen=1
|
||||
fi
|
||||
level_indicator="🐜"
|
||||
inline_logs_color="${tool_color}" # either gray or normal, a bit subdued.
|
||||
inline_logs_color="${tool_color:-}" # either gray or normal, a bit subdued.
|
||||
skip_logfile=1
|
||||
;;
|
||||
|
||||
@@ -129,12 +129,18 @@ function display_alert() {
|
||||
;;
|
||||
|
||||
*)
|
||||
level="${level:-other}" # for file logging.
|
||||
level="${level:-info}" # for file logging.
|
||||
level_indicator="🌿"
|
||||
inline_logs_color="\e[1;37m"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -n ${2} ]]; then
|
||||
extra=" [${inline_logs_color} ${2} ${normal_color:-}]"
|
||||
# extra_file=" [${inline_logs_color} ${2} ${normal_color}]" # too much color in logfile
|
||||
extra_file=" [ ${2} ]"
|
||||
fi
|
||||
|
||||
# Log to journald, if asked to.
|
||||
if [[ "${ARMBIAN_LOGS_TO_JOURNAL}" == "yes" ]]; then
|
||||
echo -e "${level}: ${1} [ ${2} ]" | sed 's/\x1b\[[0-9;]*m//g' | systemd-cat --identifier="${ARMBIAN_LOGS_JOURNAL_IDENTIFIER:-armbian}"
|
||||
@@ -150,7 +156,8 @@ function display_alert() {
|
||||
if [[ -f "${CURRENT_LOGFILE}" ]]; then
|
||||
# If not asked to skip, or debugging is enabled, log to file.
|
||||
if [[ ${skip_logfile} -lt 1 || "${DEBUG}" == "yes" ]]; then
|
||||
echo -e "--> (${SECONDS}) ${level^^}: ${1} [ ${2} ]" >> "${CURRENT_LOGFILE}" # bash ^^ is "to upper case"
|
||||
#echo -e "--> (${SECONDS}) ${level^^}: ${1} [ ${2} ]" >> "${CURRENT_LOGFILE}" # bash ^^ is "to upper case"
|
||||
echo -e "--> (${SECONDS}) ${inline_logs_color}${level^^}${normal_color}: ${1}${extra_file}" >> "${CURRENT_LOGFILE}" # bash ^^ is "to upper case"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -173,8 +180,7 @@ function display_alert() {
|
||||
bashopts_info="${tool_color}(${normal_color}$-${tool_color})" # $- is the currently active bashopts
|
||||
fi
|
||||
|
||||
[[ -n ${2} ]] && extra=" [${inline_logs_color} ${2} ${normal_color}]"
|
||||
echo -e "${normal_color}${left_marker}${padding}${level_indicator}${padding}${normal_color}${right_marker}${timing_info}${pids_info}${bashopts_info} ${normal_color}${message}${extra}${normal_color}" >&2
|
||||
echo -e "${normal_color}${left_marker:-}${padding:-}${level_indicator}${padding}${normal_color}${right_marker:-}${timing_info}${pids_info}${bashopts_info} ${normal_color}${message}${extra}${normal_color}" >&2
|
||||
|
||||
# Now write to CI, if we're running on it. Remove ANSI escapes which confuse GitHub Actions.
|
||||
if [[ "${CI}" == "true" ]] && [[ "${ci_log}" != "" ]]; then
|
||||
@@ -209,3 +215,21 @@ function logging_echo_prefix_for_pv() {
|
||||
return 0
|
||||
|
||||
}
|
||||
|
||||
## Color echo -e command
|
||||
## Black echo -e "\033[30mBlack\033[0m"
|
||||
## Bright Black echo -e "\033[90mBright Black\033[0m"
|
||||
## Red echo -e "\033[31mRed\033[0m"
|
||||
## Bright Red echo -e "\033[91mBright Red\033[0m"
|
||||
## Green echo -e "\033[32mGreen\033[0m"
|
||||
## Bright Green echo -e "\033[92mBright Green\033[0m"
|
||||
## Yellow echo -e "\033[33mYellow\033[0m"
|
||||
## Bright Yellow echo -e "\033[93mBright Yellow\033[0m"
|
||||
## Blue echo -e "\033[34mBlue\033[0m"
|
||||
## Bright Blue echo -e "\033[94mBright Blue\033[0m"
|
||||
## Magenta echo -e "\033[35mMagenta\033[0m"
|
||||
## Bright Magenta echo -e "\033[95mBright Magenta\033[0m"
|
||||
## Cyan echo -e "\033[36mCyan\033[0m"
|
||||
## Bright Cyan echo -e "\033[96mBright Cyan\033[0m"
|
||||
## White echo -e "\033[37mWhite\033[0m"
|
||||
## Bright White echo -e "\033[97mBright White\033[0m"
|
||||
|
||||
@@ -48,12 +48,15 @@ function export_markdown_logs() {
|
||||
function export_ansi_logs() {
|
||||
display_alert "Preparing ANSI log from" "${LOGDIR}" "debug"
|
||||
|
||||
declare dim_line_separator
|
||||
dim_line_separator=$(echo -e -n "${gray_color:-}")------------------------------------------------------------------------------------------------------------$(echo -e -n "${normal_color:-}")
|
||||
|
||||
cat <<- ANSI_HEADER > "${target_file}"
|
||||
# Armbian logs for ${ARMBIAN_BUILD_UUID}
|
||||
# Armbian build at $(LC_ALL=C LANG=C date) on $(hostname || true)
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
${dim_line_separator}
|
||||
# ARGs: ${ARMBIAN_ORIGINAL_ARGV[@]@Q}
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
${dim_line_separator}
|
||||
ANSI_HEADER
|
||||
|
||||
if [[ -n "$(command -v git)" && -d "${SRC}/.git" ]]; then
|
||||
@@ -61,13 +64,13 @@ function export_ansi_logs() {
|
||||
cat <<- GIT_ANSI_HEADER >> "${target_file}"
|
||||
# Last revision:
|
||||
$(LC_ALL=C LANG=C git --git-dir="${SRC}/.git" log -1 --color --format=short --decorate || true)
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
${dim_line_separator}
|
||||
# Git status:
|
||||
$(LC_ALL=C LANG=C git -c color.status=always --work-tree="${SRC}" --git-dir="${SRC}/.git" status || true)
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
${dim_line_separator}
|
||||
# Git changes:
|
||||
$(LC_ALL=C LANG=C git --work-tree="${SRC}" --git-dir="${SRC}/.git" diff -u --color || true)
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
${dim_line_separator}
|
||||
GIT_ANSI_HEADER
|
||||
fi
|
||||
|
||||
@@ -75,18 +78,31 @@ function export_ansi_logs() {
|
||||
|
||||
# Find and sort the files there, store in array one per logfile
|
||||
declare -a logfiles_array
|
||||
mapfile -t logfiles_array < <(find "${LOGDIR}" -type f | LC_ALL=C sort -h)
|
||||
mapfile -t logfiles_array < <(find "${LOGDIR}" -type f | LC_ALL=C sort -h) # "human" sorting
|
||||
|
||||
prefix_sed_contents=" $(echo -n -e "${tool_color:-}")" # spaces are significant
|
||||
declare prefix_sed_cmd="/^-->/!s/^/${prefix_sed_contents}/;"
|
||||
|
||||
declare logfile_full
|
||||
for logfile_full in "${logfiles_array[@]}"; do
|
||||
local logfile_base="$(basename "${logfile_full}")"
|
||||
# skip if logfile_base ends in ".md"; those are handled in the markdown version of logs
|
||||
[[ "${logfile_base}" =~ \.md$ ]] && continue
|
||||
[[ ! -s "${logfile_full}" ]] && continue # skip empty files
|
||||
declare logfile_base logfile_title
|
||||
logfile_base="$(basename "${logfile_full}")"
|
||||
[[ ! "${logfile_base}" =~ \.log$ ]] && continue # only .log files; others should be in Markdown logs
|
||||
|
||||
# remove everything before the second dot to produce the title
|
||||
# shellcheck disable=SC2001 # I saw, and I can't
|
||||
logfile_title="$(echo "${logfile_base}" | sed -e 's/^[^.]*\.[^.]*\.//')"
|
||||
|
||||
cat <<- ANSI_ONE_LOGFILE >> "${target_file}"
|
||||
## ${logfile_base}
|
||||
$(cat "${logfile_full}")
|
||||
------------------------------------------------------------------------------------------------------------
|
||||
$(echo -e -n "\033[94m")### ${logfile_title} $(echo -e -n "${normal_color}")
|
||||
$(cat "${logfile_full}" | sed -e "${prefix_sed_cmd}")
|
||||
${dim_line_separator}
|
||||
ANSI_ONE_LOGFILE
|
||||
done
|
||||
|
||||
display_alert "ANSI log file built; inspect it by running:" "less -R ${target_file}"
|
||||
declare target_relative_to_src
|
||||
target_relative_to_src="$(realpath --relative-to="${SRC}" "${target_file}")"
|
||||
|
||||
display_alert "ANSI log file built; inspect it by running:" "less -RS ${target_relative_to_src}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user