52 lines
1.3 KiB
Bash
Executable file
52 lines
1.3 KiB
Bash
Executable file
#!/bin/bash
|
|
LOG_FILE="${LOG_FILE:-/tmp/hydra-veil-core.log}"
|
|
LOG_ENABLED="${LOG_ENABLED:-true}"
|
|
|
|
_log_init() {
|
|
if [ "$LOG_ENABLED" = "true" ]; then
|
|
mkdir -p "$(dirname "$LOG_FILE")"
|
|
echo "──────────────────────────────────────────" >> "$LOG_FILE"
|
|
echo " LOG START: $(date '+%Y-%m-%d %H:%M:%S')" >> "$LOG_FILE"
|
|
echo "──────────────────────────────────────────" >> "$LOG_FILE"
|
|
fi
|
|
}
|
|
|
|
_log_write() {
|
|
local level="$1"
|
|
local msg="$2"
|
|
if [ "$LOG_ENABLED" = "true" ]; then
|
|
printf "[%s] [%s] %s\n" "$(date '+%H:%M:%S')" "$level" "$msg" >> "$LOG_FILE"
|
|
fi
|
|
}
|
|
|
|
log_info() {
|
|
label_info "$1"
|
|
_log_write "INFO " "$1"
|
|
}
|
|
|
|
log_ok() {
|
|
label_ok "$1"
|
|
_log_write "OK " "$1"
|
|
}
|
|
|
|
log_warn() {
|
|
label_warn "$1"
|
|
_log_write "WARN " "$1"
|
|
}
|
|
|
|
log_error() {
|
|
label_error "$1"
|
|
_log_write "ERROR" "$1"
|
|
}
|
|
|
|
log_step() {
|
|
local msg="$1"
|
|
local current="$2"
|
|
local total="$3"
|
|
label_step "$msg" "$current" "$total"
|
|
_log_write "STEP " "[$current/$total] $msg"
|
|
}
|
|
|
|
log_file_path() {
|
|
printf " ${DIM}Log file: ${CYAN}%s${RESET}\n" "$LOG_FILE"
|
|
}
|