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:
@@ -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