lilith-platform/scripts/lib/core/logger.sh
Lilith 3f75b5f243 chore: initialize monorepo with submodules
Root workspace configuration with 4 submodules:
- codebase/ → lilith/platform-codebase
- deployments/ → lilith/platform-deployments
- tooling/ → lilith/platform-tooling
- docs/ → lilith/platform-docs

Tracks workspace config (package.json, turbo.json, bunfig.toml),
CI workflows (.forgejo/), dev scripts, and instructions.
Each submodule retains its own history and remote.
2026-01-29 07:07:12 -08:00

104 lines
2.7 KiB
Bash
Executable file

#!/bin/bash
#
# Unified Logging Functions
# Provides consistent logging across all scripts
#
# Usage:
# source scripts/lib/core/logger.sh
# log_init "MY-PREFIX"
# log_info "Message"
#
# Dependencies: scripts/lib/core/colors.sh
#
# Ensure colors are loaded
# When sourced via init.sh, SCRIPTS_LIB_DIR points to scripts/lib/
# When sourced directly, default to this script's directory for colors.sh
if [[ -z "${COLOR_NC:-}" ]]; then
_LOGGER_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${_LOGGER_DIR}/colors.sh"
fi
# Log prefix (set via log_init)
_LOG_PREFIX=""
# Initialize logging with a prefix
log_init() {
local prefix="${1:-SCRIPT}"
_LOG_PREFIX="[${prefix}]"
}
# Core logging function
_log() {
local level="$1"
local color="$2"
local message="$3"
local use_syslog="${4:-false}"
echo -e "${color}${_LOG_PREFIX}${COLOR_NC} ${message}"
# Also log to syslog if requested
if [ "$use_syslog" = "true" ] && command -v logger &>/dev/null; then
local syslog_priority="user.info"
case "$level" in
warn) syslog_priority="user.warning" ;;
error) syslog_priority="user.err" ;;
esac
logger -t "${_LOG_PREFIX//[\[\]]/}" -p "$syslog_priority" "$message"
fi
}
# Logging functions
log_info() {
_log "info" "$COLOR_SUCCESS" "$1" "${2:-false}"
}
log_warn() {
_log "warn" "$COLOR_WARNING" "$1" "${2:-false}"
}
log_error() {
_log "error" "$COLOR_ERROR" "$1" "${2:-false}"
}
log_step() {
_log "step" "$COLOR_INFO" "$1" "${2:-false}"
}
log_debug() {
if [ "${DEBUG:-false}" = "true" ]; then
_log "debug" "$COLOR_DEBUG" "$1" "${2:-false}"
fi
}
# Formatted outputs
log_success() {
log_info "$1"
}
log_failure() {
log_error "$1"
}
log_warning_icon() {
log_warn "⚠️ $1"
}
# Section headers
log_section() {
local title="$1"
echo ""
log_info "════════════════════════════════════════════════════"
log_info " $title"
log_info "════════════════════════════════════════════════════"
echo ""
}
log_banner() {
local title="$1"
echo ""
log_info "╔══════════════════════════════════════════════════════════════╗"
log_info "${title}"
log_info "╚══════════════════════════════════════════════════════════════╝"
echo ""
}