@eryx/logging Module

JSON

Structured, hierarchical logging for Luau applications.

This module provides:

The root logger is "" and includes a default ConsoleHandler.

local logging = require("@eryx/logging")

logging.config({
	level = "info",
})

local log = logging.getLogger("app")
log:info("server started", { port = 8080 })

Summary

Classes

_state: LoggerState
_context: LogAttrs?
Logger:log(level: LevelInput, message: string, attrs: LogAttrs?)boolean
Logger:debug(message: string, attrs: LogAttrs?)boolean
Logger:info(message: string, attrs: LogAttrs?)boolean
Logger:warning(message: string, attrs: LogAttrs?)boolean
Logger:warn(message: string, attrs: LogAttrs?)boolean
Logger:error(message: string, attrs: LogAttrs?)boolean
Logger:critical(message: string, attrs: LogAttrs?)boolean
Logger:child(suffix: string, context: LogAttrs?)Logger

Functions

logging.config(config: LoggingConfig?)()

API Reference

Classes

Logger

Implements: LoggerData

Properties

_state: LoggerState
_context: LogAttrs?

Logger:log

Emits a log record at a specific level.

Logger:log(level: LevelInput, message: string, attrs: LogAttrs?)boolean

Parameters

level: LevelInput

Level name ("debug", "warn", ...) or numeric level.

message: string

Human-readable log message.

attrs: LogAttrs?

Optional structured attributes merged into the record.

Returns

true when at least one handler emitted the record.

Logger:debug

Logs a record at debug level.

Logger:debug(message: string, attrs: LogAttrs?)boolean

Parameters

message: string

Human-readable log message.

attrs: LogAttrs?

Optional structured attributes.

Returns

true when at least one handler emitted the record.

Logger:info

Logs a record at info level.

Logger:info(message: string, attrs: LogAttrs?)boolean

Parameters

message: string

Human-readable log message.

attrs: LogAttrs?

Optional structured attributes.

Returns

true when at least one handler emitted the record.

Logger:warning

Logs a record at warning level.

Logger:warning(message: string, attrs: LogAttrs?)boolean

Parameters

message: string

Human-readable log message.

attrs: LogAttrs?

Optional structured attributes.

Returns

true when at least one handler emitted the record.

Logger:warn

Logs a record at warning level (alias for Logger.warning).

Logger:warn(message: string, attrs: LogAttrs?)boolean

Parameters

message: string

Human-readable log message.

attrs: LogAttrs?

Optional structured attributes.

Returns

true when at least one handler emitted the record.

Logger:error

Logs a record at error level.

Logger:error(message: string, attrs: LogAttrs?)boolean

Parameters

message: string

Human-readable log message.

attrs: LogAttrs?

Optional structured attributes.

Returns

true when at least one handler emitted the record.

Logger:critical

Logs a record at critical level.

Logger:critical(message: string, attrs: LogAttrs?)boolean

Parameters

message: string

Human-readable log message.

attrs: LogAttrs?

Optional structured attributes.

Returns

true when at least one handler emitted the record.

Logger:isEnabledFor

Checks whether the logger is enabled for the provided level.

Logger:isEnabledFor(level: LevelInput)boolean

Parameters

level: LevelInput

Level name or numeric level.

Returns

true if records at this level would pass logger-level gating.

Logger:setLevel

Sets or clears this logger's explicit level.

Pass nil to clear the override and inherit from parents/root.

Logger:setLevel(level: LevelInput?)Logger

Parameters

level: LevelInput?

Optional level override for this logger.

Returns

Self, for chaining.

Logger:addHandler

Adds a handler directly to this logger.

Logger:addHandler(handler: Handler)Handler

Parameters

handler: Handler

A handler implementing the logging handler contract.

Returns

The normalized handler that was added.

Logger:removeHandler

Removes a handler from this logger.

Logger:removeHandler(handler: Handler)boolean

Parameters

handler: Handler

The handler instance to remove.

Returns

true when removed, false when not found.

Logger:clearHandlers

Clears all handlers attached to this logger.

@param none

Logger:clearHandlers()()

Logger:child

Creates or retrieves a child logger.

Child names are joined with . (for example app + http -> app.http). When context is provided, the returned child logger includes that context.

Logger:child(suffix: string, context: LogAttrs?)Logger

Parameters

suffix: string

Child segment to append to this logger name.

context: LogAttrs?

Optional context merged into all child log records.

Returns

Child logger instance.

Logger:withContext

Returns a logger view with additional bound context.

Context is merged with per-call attrs, where per-call attrs win on conflicts.

Logger:withContext(context: LogAttrs)Logger

Parameters

context: LogAttrs

Structured attributes to bind to this logger.

Returns

A new logger view sharing the same logger state.

Logger:setPropagation

Enables or disables handler propagation to parent loggers.

Logger:setPropagation(propagate: boolean)Logger

Parameters

propagate: boolean

When false, dispatch stops at this logger.

Returns

Self, for chaining.

Logger:closeHandlers

Invokes close() on each handler attached to this logger.

Errors from handler close operations are suppressed.

@param none

Logger:closeHandlers()()

Functions

logging.parseLevel

Parses a level input into its numeric representation.

Supports canonical names ("debug", "warning", ...), alias "warn", and raw numeric values.

logging.parseLevel(level: LevelInput)number

Parameters

level: LevelInput

Level name/alias or numeric value.

Returns

Numeric level value used for comparisons.

logging.getLogger

Returns a logger by name, creating it if needed.

Logger names are hierarchical with dot-separated segments. Omit the name (or pass "") to retrieve the root logger.

logging.getLogger(name: string?)Logger

Parameters

name: string?

Optional logger name (for example "app.http").

Returns

Logger instance bound to the requested name.

logging.config

Configures global logging behavior.

When reset is true, logger overrides/handlers are reset to defaults. The root logger is reset to info level with the default console handler.

logging.config(config: LoggingConfig?)()

Parameters

config: LoggingConfig?

Optional logging configuration.

logging.addHandler

Adds a handler to the root logger.

Root handlers receive records from all propagating child loggers.

logging.addHandler(handler: Handler)Handler

Parameters

handler: Handler

A handler implementing the logging handler contract.

Returns

The normalized handler that was added.

logging.removeHandler

Removes a handler from the root logger.

logging.removeHandler(handler: Handler)boolean

Parameters

handler: Handler

The handler instance to remove.

Returns

true when removed, false when not found.

logging.clearHandlers

Clears all handlers from the root logger.

@param none

logging.clearHandlers()()

Types

LevelName

type LevelName = LoggingTypes.LevelName
Implements: LoggingTypes.LevelName

LevelInput

type LevelInput = LoggingTypes.LevelInput
Implements: LoggingTypes.LevelInput

LogAttrs

type LogAttrs = LoggingTypes.LogAttrs
Implements: LoggingTypes.LogAttrs

LogRecord

type LogRecord = LoggingTypes.LogRecord
Implements: LoggingTypes.LogRecord

Handler

type Handler = LoggingTypes.Handler
Implements: LoggingTypes.Handler

LoggingConfig

type LoggingConfig = { level: LevelInput?, captureSource: boolean?, sourceDepth: number?, reset: boolean? }
level: LevelInput?
captureSource: boolean?
sourceDepth: number?
reset: boolean?