Class
Logger
A named logger that emits structured log entries scoped to a hierarchical path.
About Logger
A Logger emits structured log entries that are tagged with a hierarchical
name, letting you group related messages by subsystem or feature. Obtain a
top-level logger from LogService.GetLogger, then create nested child
loggers with Logger.GetLogger. Each logger has a short
Logger.Name and a dot-joined Logger.FullPath built from its
ancestry (for example a logger named Damage created from a logger named
Combat has the full path Combat.Damage).
local LogService = game:GetService("LogService")
local combat = LogService:GetLogger("Combat")
local damage = combat:GetLogger("Damage")
print(damage.Name) --> Damage
print(damage.FullPath) --> Combat.Damage
damage:Info("Dealt {amount} damage to {target}", {amount = 25, target = "Goblin"})
Loggers behave the same as the structured logging methods on
LogService: messages flow to the Output window, the Developer
Console, and LogService.MessageOut, and are included in
LogService.GetLogHistory tagged with the logger's full path.
Hierarchy and Propagation
When a message is logged on a logger, its Logger.MessageOut event
fires on that logger and on every ancestor up to the root. This lets you
attach a listener on a parent logger to observe all messages emitted by its
descendants. The message is emitted to the engine's output system exactly
once, tagged with the originating logger's full path.
Template Syntax and Context
The logging methods accept the same {key} template placeholders and
context tables as the structured logging methods on LogService. See
LogService for details on template syntax and how context values are
stored.
Lifetime
A logger remains valid as long as you hold a reference to it. Once all
references to a logger (and its descendants) are released, it is reclaimed,
and calling any method on a stale logger raises an error. The number of live
loggers and the length of a logger's full path are both bounded; exceeding
either limit raises an error from Logger.GetLogger.
Warning
This class might have unexpected or unreliable behavior and content might be truncated. Don't rely on contents of events and messages emitted by loggers for any important game logic.
Properties 2
Name
: stringReadOnlyNotReplicatedThe name segment of this logger within its parent.The name of this logger as supplied to
LogService.GetLoggerorLogger.GetLogger. This is a single path segment and never contains a.character. UseLogger.FullPathfor the complete dot-joined path.FullPath
: stringReadOnlyNotReplicatedThe dot-joined path of this logger from the root logger.The full path of this logger, formed by joining the
Logger.Nameof each logger from the root down to this one with.separators. For a top-level logger the full path equals its name. Messages logged through this logger are tagged with this full path inLogService.GetLogHistory.
Methods 6
GetLogger
(name: string) → LoggerReturns a child logger with the given name, creating it if it does not already exist.Returns the child logger with the given
name, creating it if it does not already exist. Calling this with the same name repeatedly returns the same logger instance for as long as a reference to it is held. The returned logger'sLogger.FullPathis this logger's full path followed by.andname.This method raises an error if the name is empty, contains a
., or contains control characters, if the resulting full path is too long, or if the maximum number of live loggers has been exceeded.local LogService = game:GetService("LogService") local network = LogService:GetLogger("Network") local http = network:GetLogger("Http") print(http.FullPath) --> Network.HttpOutput
(message: string, context: Dictionary = nil) → ()Logs a message at theMessageType.MessageOutputlevel with optional structured context.Logs a message at the
MessageType.MessageOutputlevel, tagged with this logger'sLogger.FullPath. When acontexttable is provided, template placeholders like{key}in the message are replaced with the corresponding context values, and the context is preserved as structured data for display in the Developer Console and Studio's Output window.local LogService = game:GetService("LogService") local logger = LogService:GetLogger("Shop") logger:Output("Player {name} opened the shop", {name = "Alice"}) -- Output: "Player Alice opened the shop"Info
(message: string, context: Dictionary = nil) → ()Logs a message at theMessageType.MessageInfolevel with optional structured context.Logs a message at the
MessageType.MessageInfolevel, tagged with this logger'sLogger.FullPath. When acontexttable is provided, template placeholders like{key}in the message are replaced with the corresponding context values.local LogService = game:GetService("LogService") local logger = LogService:GetLogger("Combat") logger:Info("Dealt {amount} damage", {amount = 42}) -- Output: "Dealt 42 damage"Warn
(message: string, context: Dictionary = nil) → ()Logs a message at theMessageType.MessageWarninglevel with optional structured context.Logs a message at the
MessageType.MessageWarninglevel, tagged with this logger'sLogger.FullPath. When acontexttable is provided, template placeholders like{key}in the message are replaced with the corresponding context values.local LogService = game:GetService("LogService") local logger = LogService:GetLogger("Combat") logger:Warn("Health low: {hp}", {hp = 5}) -- Output: "Health low: 5"Error
(message: string, context: Dictionary = nil) → ()Logs a message at theMessageType.MessageErrorlevel with optional structured context.Logs a message at the
MessageType.MessageErrorlevel, tagged with this logger'sLogger.FullPath. UnlikeLogService.Error, this method emits an error-level log entry and returns normally; it does not throw. When acontexttable is provided, template placeholders like{key}in the message are replaced with the corresponding context values.local LogService = game:GetService("LogService") local logger = LogService:GetLogger("Network") logger:Error("Request failed: {reason}", {reason = "timeout"}) -- Emits an error-level log; execution continues.Log
(messageType: MessageType, message: string, context: Dictionary = nil) → ()Logs a message at the specified level with optional structured context.Logs a message at the specified
MessageTypelevel, tagged with this logger'sLogger.FullPath. This is a general-purpose method that combinesOutput(),Info(),Warn(), andError()into a single call with an explicit message type parameter. UnlikeLogService.Log, passingMessageType.MessageErroremits an error-level log and returns normally rather than throwing.local LogService = game:GetService("LogService") local logger = LogService:GetLogger("Combat") logger:Log(Enum.MessageType.MessageInfo, "Event {action}", {action = "spawn"})
Events 1
MessageOut
Logger.MessageOut:Connect(function(message, messageType, context))Fires when a message is logged through this logger or any of its descendants.Fires whenever a message is logged through this logger or any logger beneath it in the hierarchy. Because a logged message fires
MessageOuton the originating logger and each of its ancestors, a listener attached to a parent logger observes every message emitted by its descendants. Themessageparameter contains the fully rendered text (template placeholders already replaced), and thecontextparameter carries the structured key-value pairs when the message was logged with a context table; otherwise it is nil.local LogService = game:GetService("LogService") local combat = LogService:GetLogger("Combat") combat.MessageOut:Connect(function(message, messageType, context) print("[Combat]", message) end) -- A message logged on a descendant also fires the parent's MessageOut. combat:GetLogger("Damage"):Info("Hit for {amount}", {amount = 10}) -- Prints: [Combat] Hit for 10
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.