Skip to content

Petrichor.Log

Petrichor.Log writes tagged messages to the game log.

Loading#

local Log = require("Petrichor.Log")
import * as Log from "Petrichor.Log"

Functions#

Log.info(tag, msg)#

Writes an informational message.

Parameter Type Description
tag string Short identifier for your mod or subsystem (e.g. "my-mod")
msg string The message body
Log.info("my-mod", "Mod loaded successfully")
-- Output: [my-mod] Mod loaded successfully
Log.info("my-mod", "Mod loaded successfully")
// Output: [my-mod] Mod loaded successfully

Log.warn(tag, msg)#

Writes a warning message. The output is prefixed with [warn].

Log.warn("my-mod", "Expected field not found, using default")
-- Output: [my-mod] [warn] Expected field not found, using default
Log.warn("my-mod", "Expected field not found, using default")
// Output: [my-mod] [warn] Expected field not found, using default

Log.debug(tag, msg)#

Writes a debug message. Used by Petrichor.Standard when log(Levels.DEBUG, ...).

Log.debug("my-mod", "verbose trace")
Log.debug("my-mod", "verbose trace")

Log.err(tag, msg)#

Writes an error message. The output is prefixed with [err].

Log.err("my-mod", "Hook registration failed for Foo::bar")
-- Output: [my-mod] [err] Hook registration failed for Foo::bar
Log.err("my-mod", "Hook registration failed for Foo::bar")
// Output: [my-mod] [err] Hook registration failed for Foo::bar

Conventions#

  • Keep tag short and consistent. It appears on every line.
  • Use Log.info for normal lifecycle events (mod loaded, hook fired once, etc.).
  • Use Log.warn for unexpected but recoverable situations.
  • Use Log.err for failures. The mod keeps running, no exception is thrown.
local Mixin = require("Augment.Mixin")
local Log  = require("Petrichor.Log")

local TAG = "cow-patch"

Log.info(TAG, "registering hooks")

local ok = Mixin.register("daCow_c::Execute", "before", function(ctx)
    Log.info(TAG, "cow Execute fired")
end, 0, TAG)

if not ok then
    Log.err(TAG, "failed to register daCow_c::Execute hook")
end
import * as Mixin from "Augment.Mixin"
import * as Log from "Petrichor.Log"

const TAG = "cow-patch"

Log.info(TAG, "registering hooks")

const ok = Mixin.register("daCow_c::Execute", "before", (ctx) => {
    Log.info(TAG, "cow Execute fired")
}, 0, TAG)

if (!ok) {
    Log.err(TAG, "failed to register daCow_c::Execute hook")
}