Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDefaultLogger ¶
GetDefaultLogger: returns the default logger instance, initializing it if necessary. The default logger uses:
- os.Stderr for output
- RFC3339 timestamp format
- Caller reporting enabled
- TextFormatter by default, or JSONFormatter if LOG_FORMAT=json env var is set
You can use this to get the default logger and add fields before injecting:
logger := logmodule.GetDefaultLogger().With("app", "myapp")
logmodule.InjectLogger(L, logger)
func InjectLogger ¶
InjectLogger: injects a pre-configured logger instance into the Lua state. This is OPTIONAL - if you don't inject a logger, a default one will be created automatically. Use this only when you want to add pre-set fields (like request ID, user ID, etc.) from Go.
Example usage:
// Get default logger and add fields
logger := logmodule.GetDefaultLogger().With("request_id", "abc123", "user", "john")
logmodule.InjectLogger(L, logger)
Or create a custom logger:
logger := logmodule.NewLogger(os.Stderr, true, time.RFC3339, log.TextFormatter)
logger = logger.With("app", "myapp", "version", "1.0.0")
logmodule.InjectLogger(L, logger)
func Loader ¶
Loader: creates and returns the log module for Lua. This function should be registered with L.PreloadModule("log", log.Loader)
@luamodule log
Example usage in Lua:
local log = require("log")
log.info("Application started")
log.warn("Low memory warning")
log.error("Failed to connect to database")
-- Or get a logger object
local logger = log.logger()
logger:info("Using logger object")
local contextLogger = logger:with("request_id", "abc123")
contextLogger:info("Request processing")
Types ¶
This section is empty.