-
Notifications
You must be signed in to change notification settings - Fork 0
API Logger
Logger is the framework's small structured logging utility: per-instance history buffer, runtime severity gating, timestamped console lines, and optional operation correlation via OperationId.
Important
Docs audit note (2026-05): This page was re-audited against FSM/Orchestrator/Core/Logger.luau and FSM/Orchestrator/Core/Settings.luau.
The module has two layers:
-
static bootstrap β
Logger.Initialize(Util)cachesUtil.Settings.Logger -
per-instance logging β
Logger.new({ Name? })creates a logger with its ownHistory
Implementation constants in the current source:
SHOW_TIMESTAMP = trueUSE_RICH_TEXT = falseMAX_LOG_HISTORY = 500
Important runtime rules:
- every call to
:Log(...)is appended to history before output filtering - console output is controlled by
Settings.Logger.DebuggingEnabled - severity gating is controlled by
Settings.Logger.MinimumLoggingLevel -
ERRORuseswarn(), not Luaerror()
Logger.Initialize(Util: { Settings: { Logger: { DebuggingEnabled: boolean, MinimumLoggingLevel: number } } }) -> ()
Must run before any logger instance calls :Log(...).
Side effects
- sets the module-local
Settings = Util.Settings.Logger - marks the module as initialized
Edge cases
- second call is a no-op
-
Logger.new(...)can be called before initialization, but:Log(...)will assert until initialization happened
Creates a logger instance.
Fields created on the instance
SourceHistory
Name resolution
- if
params.Nameis provided, it is used directly - otherwise the module inspects
debug.info(2, "s")and keeps the final dotted path segment - if source detection fails,
Sourcemay benil
local log = Logger.new({ Name = "InventoryService" })
local auto = Logger.new({})Records an entry and optionally prints it.
Stored history shape
{
Timestamp = os.time(),
OperationId = params.OperationId,
Level = params.Level or "INFO",
Message = params.Message or "",
Data = params.Data,
}Console formatting
- printed prefix is
[HH:MM:SS] [LEVEL] [Source] -
OperationIdis appended as(<id>)when it is a string -
INFOandDEBUGprint withprint() -
WARNandERRORprint withwarn() - unknown levels print as
[UNKNOWN (<level>)]
Severity gate
| Level | Printed when MinimumLoggingLevel >=
|
|---|---|
ERROR |
1 |
WARN |
2 |
INFO |
3 |
DEBUG |
4 |
Side effects
- appends to
self.History - trims oldest entry when history exceeds 500 items
- may print or warn
Failure mode
- asserts if
Logger.Initialize(...)never ran orSettings.Loggerhas the wrong shape
log:Log({ Level = "INFO", Message = "Entity spawned" })
log:Log({ Level = "ERROR", Message = "Save failed", OperationId = "user:42", Data = { key = "Player_42" } })Mutates the shared logger settings table at runtime.
Important
- this affects all logger instances because they all read the same
Settings.Loggertable - history collection is unaffected; only console gating changes
log:SetMinimumLoggingLevel(4) -- enable DEBUG output globallyReturns the live history array for this logger.
Edge cases
- returns the actual internal table, not a copy
- empty logger =>
{} - each logger instance has its own independent history
local history = table.clone(log:GetHistory())| Method | Signature | Returns | Notes |
|---|---|---|---|
Initialize |
(Util) -> () |
() |
one-time bootstrap |
new |
({ Name: string? }) -> Logger |
Logger |
auto-detects source if omitted |
Log |
({ Level, Message, OperationId?, Data? }) -> () |
() |
always writes to history first |
SetMinimumLoggingLevel |
(level: number) -> () |
() |
global setting mutation |
GetHistory |
() -> {LogEntry} |
{LogEntry} |
live reference |
Settings live in FSM/Orchestrator/Core/Settings.luau under Logger.
| Key | Default | Meaning |
|---|---|---|
DebuggingEnabled |
true |
master on/off switch for console output |
MinimumLoggingLevel |
3 |
prints INFO, WARN, and ERROR by default; DEBUG stays hidden |
local Logger = require(path.to.Logger)
local Settings = require(path.to.Settings)
Logger.Initialize({ Settings = Settings })
local log = Logger.new({ Name = "Matchmaking" })
log:Log({ Level = "INFO", Message = "Queue opened" })local opId = "user:42"
log:Log({ Level = "INFO", Message = "Save started", OperationId = opId })
log:Log({ Level = "WARN", Message = "Retrying write", OperationId = opId })
log:Log({ Level = "INFO", Message = "Save finished", OperationId = opId })local last = log:GetHistory()[#log:GetHistory()]
assert(last.Level == "INFO")
assert(last.Message == "Queue opened")-
History is always written. Disabling console output does not disable history collection.
-
ERRORdoes not stop execution. If you need hard failure semantics, log first and callerror(...)separately. -
History trimming is O(n). Once the buffer is full, every new entry removes index 1. Avoid frame-by-frame logging.
-
SetMinimumLoggingLevelis global. It is not scoped to one logger instance. -
GetHistory()returns a live reference. Clone it before filtering or mutating.
Quick Links: Home Β· Quick Start Β· API Reference Β· Architecture Β· Examples Β· Glossary
Copyright: Β© 2026 RBXStateMachine contributors Β· Repository Β· License information