diff --git a/src/lua/asobi_lua_api.erl b/src/lua/asobi_lua_api.erl index 975f162..895f8a8 100644 --- a/src/lua/asobi_lua_api.erl +++ b/src/lua/asobi_lua_api.erl @@ -63,6 +63,8 @@ game.terrain.preload(coords_list) -- preload chunks async ``` """. +-include_lib("kernel/include/logger.hrl"). + -export([install/2]). -export([deep_decode/1, decode_to_map/2]). @@ -734,7 +736,7 @@ decode_to_map(Term, LuaSt) -> [] -> #{}; L when is_list(L) -> - logger:warning(#{ + ?LOG_WARNING(#{ msg => ~"asobi_lua decode_to_map: expected map, got list — coercing to #{}", length => length(L) }), diff --git a/src/lua/asobi_lua_match.erl b/src/lua/asobi_lua_match.erl index d549390..f3418f9 100644 --- a/src/lua/asobi_lua_match.erl +++ b/src/lua/asobi_lua_match.erl @@ -35,6 +35,8 @@ function vote_resolved(template, result, state) -- return updated state -behaviour(asobi_match). +-include_lib("kernel/include/logger.hrl"). + -export([init/1, join/2, leave/2, handle_input/3, tick/1, get_state/2]). -export([vote_requested/1, vote_resolved/3]). @@ -57,7 +59,7 @@ init(Config) -> P when is_binary(P); is_list(P) -> P; undefined -> - logger:error(#{msg => ~"asobi_lua_match init: missing lua_script", config => Config}), + ?LOG_ERROR(#{msg => ~"asobi_lua_match init: missing lua_script", config => Config}), erlang:error({missing_lua_script, Config}) end, GameConfig = maps:get(game_config, Config, #{}), @@ -80,13 +82,13 @@ init(Config) -> {ok, [], _} -> %% asobi_match:init/1 doesn't allow an error return; log and %% crash so the supervisor handles it with full context. - logger:error(#{ + ?LOG_ERROR(#{ msg => ~"asobi_lua_match init: lua init() returned no value", script => ScriptPath }), erlang:error({lua_error, ~"init() must return a table"}); {error, Reason} -> - logger:error(#{ + ?LOG_ERROR(#{ msg => ~"asobi_lua_match init: lua init() failed", script => ScriptPath, reason => Reason @@ -94,7 +96,7 @@ init(Config) -> erlang:error({lua_init_failed, Reason}) end; {error, Reason} -> - logger:error(#{ + ?LOG_ERROR(#{ msg => ~"asobi_lua_match init: lua_loader:new/1 failed", script => ScriptPath, reason => Reason @@ -108,7 +110,7 @@ join(PlayerId, #{lua_state := LuaSt, game_state := GS} = State) -> {ok, [GS1 | _], LuaSt1} -> {ok, State#{lua_state => LuaSt1, game_state => GS1}}; {error, Reason} -> - logger:warning(#{msg => ~"lua join error", player_id => PlayerId, reason => Reason}), + ?LOG_WARNING(#{msg => ~"lua join error", player_id => PlayerId, reason => Reason}), {error, Reason} end. @@ -118,7 +120,7 @@ leave(PlayerId, #{lua_state := LuaSt, game_state := GS} = State) -> {ok, [GS1 | _], LuaSt1} -> {ok, State#{lua_state => LuaSt1, game_state => GS1}}; {error, Reason} -> - logger:warning(#{msg => ~"lua leave error", player_id => PlayerId, reason => Reason}), + ?LOG_WARNING(#{msg => ~"lua leave error", player_id => PlayerId, reason => Reason}), {ok, State} end. @@ -131,7 +133,7 @@ handle_input(PlayerId, Input, #{lua_state := LuaSt, game_state := GS} = State) - {ok, [GS1 | _], LuaSt2} -> {ok, State#{lua_state => LuaSt2, game_state => GS1}}; {error, Reason} -> - logger:warning(#{ + ?LOG_WARNING(#{ msg => ~"lua input error", player_id => PlayerId, reason => Reason }), {ok, State} @@ -149,10 +151,10 @@ tick(State0) -> {ok, State#{lua_state => LuaSt1, game_state => GS1}} end; {error, timeout} -> - logger:error(#{msg => ~"lua tick timeout", script => maps:get(script, State)}), + ?LOG_ERROR(#{msg => ~"lua tick timeout", script => maps:get(script, State)}), {ok, State}; {error, Reason} -> - logger:error(#{msg => ~"lua tick error", reason => Reason}), + ?LOG_ERROR(#{msg => ~"lua tick error", reason => Reason}), {ok, State} end. diff --git a/src/lua/asobi_lua_reload.erl b/src/lua/asobi_lua_reload.erl index fb0ba85..4067e7d 100644 --- a/src/lua/asobi_lua_reload.erl +++ b/src/lua/asobi_lua_reload.erl @@ -54,6 +54,8 @@ per-tick stat overhead can set `asobi_lua.reload_mode` (or the changes are container restarts. The per-tick `stat()` is skipped. """. +-include_lib("kernel/include/logger.hrl"). + -export([maybe_hot_reload/1]). %% Reload runs script-author code under a wall-clock budget. A `while true do @@ -78,12 +80,12 @@ do_maybe_reload(#{script := Path, script_mtime := OldMtime, lua_state := LuaSt} NewMtime -> case reload_script(Path, LuaSt) of {ok, NewLuaSt} -> - logger:notice(#{ + ?LOG_NOTICE(#{ msg => ~"lua hot reload", script => Path, mtime => NewMtime }), State#{lua_state => NewLuaSt, script_mtime => NewMtime}; {error, Reason} -> - logger:warning(#{ + ?LOG_WARNING(#{ msg => ~"lua hot reload failed", script => Path, reason => Reason diff --git a/src/lua/asobi_lua_world.erl b/src/lua/asobi_lua_world.erl index 93f2473..19ddab6 100644 --- a/src/lua/asobi_lua_world.erl +++ b/src/lua/asobi_lua_world.erl @@ -30,6 +30,8 @@ function on_zone_unloaded(cx, cy, state) -- return state -behaviour(asobi_world). +-include_lib("kernel/include/logger.hrl"). + -export([init/1, join/2, leave/2, spawn_position/2]). -export([zone_tick/2, handle_input/3, post_tick/2]). -export([generate_world/2, get_state/2]). @@ -59,7 +61,7 @@ init(Config) -> P when is_binary(P); is_list(P) -> P; undefined -> - logger:error(#{msg => ~"asobi_lua_world init: missing lua_script", config => Config}), + ?LOG_ERROR(#{msg => ~"asobi_lua_world init: missing lua_script", config => Config}), erlang:error({missing_lua_script, Config}) end, GameConfig = maps:get(game_config, Config, #{}), @@ -76,13 +78,13 @@ init(Config) -> script_mtime => filelib:last_modified(ScriptPath) }}; {ok, [], _} -> - logger:error(#{ + ?LOG_ERROR(#{ msg => ~"asobi_lua_world init: lua init() returned no value", script => ScriptPath }), erlang:error({lua_error, ~"init() must return a table"}); {error, Reason} -> - logger:error(#{ + ?LOG_ERROR(#{ msg => ~"asobi_lua_world init: lua init() failed", script => ScriptPath, reason => Reason @@ -90,7 +92,7 @@ init(Config) -> erlang:error({lua_init_failed, Reason}) end; {error, Reason} -> - logger:error(#{ + ?LOG_ERROR(#{ msg => ~"asobi_lua_world init: lua_loader:new/1 failed", script => ScriptPath, reason => Reason @@ -251,7 +253,7 @@ generate_world(Seed, Config) when is_map(Config) -> {ok, ZoneStates} = generate_world(Seed, #{lua_state => LuaSt}), {ok, inject_per_zone_lua(ZoneStates, ScriptPath, PreInstall)}; {error, Reason} -> - logger:error(#{ + ?LOG_ERROR(#{ msg => ~"asobi_lua_world generate_world: lua_loader:new failed; world will spawn with empty zones", script => ScriptPath, @@ -425,7 +427,7 @@ decode_terrain_provider(Result, LuaSt) -> end, {Mod, ProvArgs}; not_allowed -> - logger:warning(#{ + ?LOG_WARNING(#{ msg => ~"terrain_provider_not_allowed", requested => ModBin }), @@ -471,7 +473,7 @@ log_lua_error(Callback, Reason, StateOrZoneState) -> timeout -> ~"timeout"; _ -> ~"error" end, - logger:warning(#{ + ?LOG_WARNING(#{ msg => ~"lua callback failed", callback => Callback, severity => Severity, @@ -559,7 +561,7 @@ decode_phases(PhasesRef, LuaSt) -> %% type helps the developer notice it; without this, decode silently %% returned [], the world server treated it as "no phases", and the %% mismatch only surfaced as runtime weirdness much later. - logger:warning(#{ + ?LOG_WARNING(#{ msg => ~"asobi_lua_world: phases() returned non-list, ignoring", got_type => type_of(Other) }),