#!/usr/bin/env bash
# tool/logs -- recent activity, newest last
set -o pipefail
SELF=$(readlink -f "${BASH_SOURCE[0]}")
NV_BASE=$(cd "$(dirname "$SELF")/../../.." && pwd)
export NV_BASE
# shellcheck source=/dev/null
. "$NV_BASE/lib/core/bootstrap.sh"

ui_header "$(t mod_tool_logs)" "$NV_LOG_FILE"

if [ ! -r "$NV_LOG_FILE" ]; then
    ui_info "$(t logs_empty)"
    exit 0
fi

ui_section "$(t logs_errors)"
grep -E ' (ERROR|WARN) ' "$NV_LOG_FILE" 2>/dev/null | tail -n 15 | sed 's/^/  /'
[ -z "$(grep -E ' (ERROR|WARN) ' "$NV_LOG_FILE" 2>/dev/null)" ] && ui_ok "$(t logs_no_errors)"

ui_section "$(t logs_recent)"
tail -n 20 "$NV_LOG_FILE" 2>/dev/null | sed 's/^/  /'
ui_blank
exit 0
