Logger API
Log messages from Lua scripts with different severity levels.
Functions
info
logger:info(message: string) -> ()
Log an info message.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Message to log |
Example:
logger:info("Script started")
logger:info("Found item: " .. item:name())
warn
logger:warn(message: string) -> ()
Log a warning message.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Warning message |
Example:
logger:warn("Inventory almost full")
logger:warn("Health low: " .. combat:current_health())
error
logger:error(message: string) -> ()
Log an error message.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Error message |
Example:
logger:error("Failed to find NPC")
logger:error("Script encountered an error")
debug
logger:debug(message: string) -> ()
Log a debug message (only shown in debug mode).
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Debug message |
Example:
logger:debug("Variable value: " .. tostring(variable))
logger:debug("Function called with parameter: " .. param)
Common Patterns
Status Logging
local function log_status(label, value)
logger:info(label .. ": " .. tostring(value))
end
log_status("Current HP", combat:current_health())
log_status("Inventory items", inventory:item_count())
log_status("Prayer points", skills:current_level("Prayer"))
Error Handling with Logging
local function safe_operation()
local npc = npcs:find_nearest()
if not npc then
logger:error("No NPCs found")
return false
end
if not npc:is_valid() then
logger:warn("NPC became invalid")
return false
end
logger:info("Found NPC: " .. npc:name())
return true
end
Progress Tracking
local function track_progress(current, total, label)
local percent = math.floor((current / total) * 100)
logger:info(label .. ": " .. current .. "/" .. total .. " (" .. percent .. "%)")
end
local items = 45
local target = 100
track_progress(items, target, "Items collected")
Debug Information
local function debug_player_state()
local player = players:local_player()
if not player then
logger:error("Player not found")
return
end
logger:debug("Player name: " .. player:name())
logger:debug("Position: " .. player:x() .. ", " .. player:y())
logger:debug("Health: " .. combat:current_health() .. "/" .. combat:max_health())
logger:debug("Animating: " .. tostring(player:is_animating()))
end
Conditional Logging
local function log_if_condition(condition, level, message)
if condition then
if level == "info" then
logger:info(message)
elseif level == "warn" then
logger:warn(message)
elseif level == "error" then
logger:error(message)
end
end
end
log_if_condition(inventory:full(), "warn", "Inventory full!")
log_if_condition(combat:is_low_health(20), "error", "Critical health!")
Performance Logging
local function log_performance(operation_name, start_time)
local duration = os.time() - start_time
logger:info(operation_name .. " took " .. duration .. " seconds")
end
local start = os.time()
-- Do something
log_performance("Bank deposit", start)
Structured Logging
local function log_event(event_type, details)
local message = "[" .. event_type .. "] "
for key, value in pairs(details) do
message = message .. key .. "=" .. tostring(value) .. " "
end
logger:info(message)
end
log_event("ITEM_FOUND", {
name = "Dragon bones",
quantity = 5,
distance = 8
})
Log Output
Messages are logged to:
- Console - Visible in the application UI
- Log File -
pow.login the script directory - Script Output - Captured by the desktop application
Related APIs
- Paint API - On-screen overlays
- Stats API - Script statistics