Files
Baradb/src/barabadb/core/logging.nim
T
dimgigov 422df08ab9 feat: clean build + crossmodal.tla + TLA+ symmetry (v1.0.0-prep)
Build warnings cleanup (0 warnings):
- Suppress threadpool deprecation warning (baradadb.nim)
- Remove unused 'os' import (logging.nim)
- Fix ImplicitDefaultValue for newNode params (ast.nim)
- Add explicit cstring cast for posix.open (wal.nim)
- Fix HoleEnumConv for MsgKind parsing (server.nim)

TLA+ Formal Verification:
- Add symmetry reduction (Permutations) to all 9 existing specs
- Add SYMMETRY directive to all .cfg files
- New crossmodal.tla: cross-modal consistency spec
  * MetadataVectorConsistency, HybridResultValid
  * CommittedAtomicity, AbortedAtomicity, TxnStateValid
- New models/crossmodal.cfg

Tests:
- Add Cross-Modal TLA+ Faithfulness tests (4 tests)

Docs:
- Update PLAN.md and BUG_AUDIT.md with completed tasks
2026-05-13 09:24:04 +03:00

49 lines
1.2 KiB
Nim

## BaraDB Structured JSON Logger
import std/json
import std/times
type
LogLevel* = enum
llDebug = 0
llInfo = 1
llWarn = 2
llError = 3
Logger* = ref object
level*: LogLevel
output*: File
var defaultLogger* = Logger(level: llInfo, output: stdout)
proc newLogger*(level: LogLevel = llInfo, filepath: string = ""): Logger =
var f = stdout
if filepath.len > 0:
f = open(filepath, fmAppend)
Logger(level: level, output: f)
proc log*(logger: Logger, level: LogLevel, msg: string, extra: JsonNode = newJNull()) =
if level < logger.level: return
let entry = %*{
"ts": $now(),
"level": $level,
"msg": msg,
"extra": extra
}
logger.output.writeLine($entry)
logger.output.flushFile()
proc log*(msg: string, level: LogLevel = llInfo) =
defaultLogger.log(level, msg)
proc debug*(msg: string) = defaultLogger.log(llDebug, msg)
proc info*(msg: string) = defaultLogger.log(llInfo, msg)
proc warn*(msg: string) = defaultLogger.log(llWarn, msg)
proc errorMsg*(msg: string) = defaultLogger.log(llError, msg)
proc setLevel*(logger: Logger, level: LogLevel) =
logger.level = level
proc close*(logger: Logger) =
if logger.output != stdout:
logger.output.close()