prvng_core/nulib/lib_provisioning/utils/logging.nu
Jesús Pérez 48c82ac79a
refactor(10 files): selective imports batch 4 (ADR-025 L2)
10 utils/* + workspace/migrate_to_kcl + mode/* files.

Selective imports:
  utils/imports.nu    accessor/functions [get-providers-path get-prov-lib-path get-core-nulib-path]
  utils/logging.nu    accessor/core [config-get]
  utils/generate.nu   accessor/functions [2 symbols]
  utils/files.nu      accessor/core [config-get] + secrets/lib [decode_secret_file]
  utils/qr.nu         accessor/functions [get-provisioning-url]
  utils/undefined.nu  interface + init (kept); accessor DEAD
  utils/interface.nu  accessor/core [config-get] + accessor/functions [get-provisioning-url] + logging [is-debug-enabled]

Dead imports dropped:
  workspace/migrate_to_kcl.nu   config/accessor
  mode/commands.nu              utils/logging
  mode/validator.nu             utils/logging

Validation: all 10 match pre-existing baselines (25/50/42/2 for noisy files,
0 for the others). No new errors.

Refs: ADR-025
2026-04-17 12:20:21 +01:00

121 lines
3.8 KiB
Text
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Enhanced logging system for provisioning tool
# Selective imports (ADR-025 Phase 3 Layer 2).
use lib_provisioning/config/accessor/core.nu [config-get]
# Check if debug mode is enabled
export def is-debug-enabled [] {
let raw = ($env.PROVISIONING_DEBUG? | default false)
let env_debug = if ($raw | describe) == "string" { $raw == "true" or $raw == "1" } else { $raw | into bool }
let config_debug = (config-get "debug.enabled" false)
$env_debug or $config_debug
}
# Check if debug-check mode is enabled (local task/service simulation)
export def is-debug-check-enabled [] {
$env.PROVISIONING_DEBUG_CHECK? | default false | into bool
}
# Check if metadata mode is enabled (for detailed error spans/metadata)
export def is-metadata-enabled [] {
let env_metadata = ($env.PROVISIONING_METADATA? | default false)
let config_metadata = (config-get "debug.metadata" false)
$env_metadata or $config_metadata
}
# Enable debug mode
export def set-debug-enabled [value: bool] {
$env.PROVISIONING_DEBUG = $value
}
# Enable metadata mode
export def set-metadata-enabled [value: bool] {
$env.PROVISIONING_METADATA = $value
}
export def log-info [
message: string
context?: string
] {
let timestamp = (date now | format date '%Y-%m-%d %H:%M:%S')
let context_str = if ($context | is-not-empty) { $" [($context)]" } else { "" }
print $" ($timestamp)($context_str) ($message)"
}
export def log-success [
message: string
context?: string
] {
let timestamp = (date now | format date '%Y-%m-%d %H:%M:%S')
let context_str = if ($context | is-not-empty) { $" [($context)]" } else { "" }
print $"✅ ($timestamp)($context_str) ($message)"
}
export def log-warning [
message: string
context?: string
] {
let timestamp = (date now | format date '%Y-%m-%d %H:%M:%S')
let context_str = if ($context | is-not-empty) { $" [($context)]" } else { "" }
print $"⚠️ ($timestamp)($context_str) ($message)"
}
export def log-error [
message: string
context?: string
details?: string
] {
let timestamp = (date now | format date '%Y-%m-%d %H:%M:%S')
let context_str = if ($context | is-not-empty) { $" [($context)]" } else { "" }
let details_str = if ($details | is-not-empty) { $"\n Details: ($details)" } else { "" }
print $"🛑 ($timestamp)($context_str) ($message)($details_str)"
}
export def log-debug [
message: string
context?: string
] {
if (is-debug-enabled) {
let timestamp = (date now | format date '%Y-%m-%d %H:%M:%S')
let context_str = if ($context | is-not-empty) { $" [($context)]" } else { "" }
print $"🐛 ($timestamp)($context_str) ($message)"
}
}
export def log-step [
step: string
total_steps: int
current_step: int
context?: string
] {
let progress = $"($current_step)/($total_steps)"
let context_str = if ($context | is-not-empty) { $" [($context)]" } else { "" }
print $"🔄 ($progress)($context_str) ($step)"
}
export def log-progress [
message: string
percent: int
context?: string
] {
let context_str = if ($context | is-not-empty) { $" [($context)]" } else { "" }
print $"📊 ($context_str) ($message) ($percent)%"
}
export def log-section [
title: string
context?: string
] {
let context_str = if ($context | is-not-empty) { $" [($context)]" } else { "" }
print $""
print $"📋 ($context_str) ($title)"
print $"─────────────────────────────────────────────────────────────"
}
export def log-subsection [
title: string
context?: string
] {
let context_str = if ($context | is-not-empty) { $" [($context)]" } else { "" }
print $" 📌 ($context_str) ($title)"
}