#!/usr/bin/env bash

readonly clrRed='\033[0;31m'
readonly clrGreen='\033[0;32m'
readonly clrYellow='\033[1;33m'
readonly clrBlue='\033[0;34m'
readonly clrCyan='\033[0;36m'
readonly clrBold='\033[1m'
readonly clrReset='\033[0m'

stpLogFile="${stpLogFile:-/tmp/stp-$(date +%Y%m%d-%H%M%S).log}"
export stpLogFile

log::emit() {
    local level="$1" color="$2" symbol="$3"
    shift 3
    local message="$*"
    local timestamp
    timestamp="$(date '+%H:%M:%S')"
    printf "${color}${symbol}${clrReset} %s\n" "$message"
    printf "[%s] [%-5s] %s\n" "$timestamp" "$level" "$message" >> "$stpLogFile"
}

log::step()  { log::emit "STEP"  "${clrBold}${clrBlue}"   "==>" "$@"; }
log::info()  { log::emit "INFO"  "${clrCyan}"               " -> " "$@"; }
log::ok()    { log::emit "OK"    "${clrGreen}"               " ✓  " "$@"; }
log::warn()  { log::emit "WARN"  "${clrYellow}"              " !  " "$@"; }
log::error() { log::emit "ERROR" "${clrRed}"                 " ✗  " "$@"; }
