log

package
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultLogger

func GetDefaultLogger() *log.Logger

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

func InjectLogger(L *lua.LState, logger *log.Logger)

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

func Loader(L *lua.LState) int

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL