-module(glight). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([logger/0, with/3, configure/1, emergency/2, alert/2, critical/2, error/2, warning/2, notice/2, info/2, debug/2, set_log_level/1, set_is_color/1, set_json_time_key/1, set_json_msg_key/1, set_json_level_key/1]). -export_type([log_level/0, transport/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -type log_level() :: emergency | alert | critical | error | warning | notice | info | debug. -type transport() :: console | {file, binary()}. -file("src/glight.gleam", 22). -spec logger() -> gleam@dict:dict(binary(), binary()). logger() -> maps:new(). -file("src/glight.gleam", 28). ?DOC( " This function accumulates structured data for the log message. This data\n" " will show up keyed in the json logs and formatted nicely in the console logs.\n" ). -spec with(gleam@dict:dict(binary(), binary()), binary(), binary()) -> gleam@dict:dict(binary(), binary()). with(Logger, Key, Value) -> gleam@dict:insert(Logger, Key, Value). -file("src/glight.gleam", 102). ?DOC( " Configure the Erlang logger with provided transports and set the logging\n" " level to `Info`.\n" ). -spec configure(list(transport())) -> nil. configure(Transports) -> glight_ffi:configure(Transports), nil. -file("src/glight.gleam", 114). ?DOC( " Log a message to the Erlang logger at the given log level.\n" "\n" " Prefer to use public wrappers\n" ). -spec log(log_level(), gleam@dict:dict(binary(), binary())) -> nil. log(Level, Message) -> logger:log(Level, Message), nil. -file("src/glight.gleam", 35). ?DOC( " Log at the emergency level. See the erlang log level documentation for \n" " more information and context.\n" " https://www.erlang.org/doc/apps/kernel/logger_chapter.html#log-level\n" ). -spec emergency(gleam@dict:dict(binary(), binary()), binary()) -> gleam@dict:dict(binary(), binary()). emergency(Logger, Message) -> log(emergency, gleam@dict:insert(Logger, <<"msg"/utf8>>, Message)), Logger. -file("src/glight.gleam", 43). ?DOC( " Log at the alert level. See the erlang log level documentation for \n" " more information and context.\n" " https://www.erlang.org/doc/apps/kernel/logger_chapter.html#log-level\n" ). -spec alert(gleam@dict:dict(binary(), binary()), binary()) -> gleam@dict:dict(binary(), binary()). alert(Logger, Message) -> log(alert, gleam@dict:insert(Logger, <<"msg"/utf8>>, Message)), Logger. -file("src/glight.gleam", 51). ?DOC( " Log at the critical level. See the erlang log level documentation for \n" " more information and context.\n" " https://www.erlang.org/doc/apps/kernel/logger_chapter.html#log-level\n" ). -spec critical(gleam@dict:dict(binary(), binary()), binary()) -> gleam@dict:dict(binary(), binary()). critical(Logger, Message) -> log(critical, gleam@dict:insert(Logger, <<"msg"/utf8>>, Message)), Logger. -file("src/glight.gleam", 59). ?DOC( " Log at the error level. See the erlang log level documentation for \n" " more information and context.\n" " https://www.erlang.org/doc/apps/kernel/logger_chapter.html#log-level\n" ). -spec error(gleam@dict:dict(binary(), binary()), binary()) -> gleam@dict:dict(binary(), binary()). error(Logger, Message) -> log(error, gleam@dict:insert(Logger, <<"msg"/utf8>>, Message)), Logger. -file("src/glight.gleam", 67). ?DOC( " Log at the warning level. See the erlang log level documentation for \n" " more information and context.\n" " https://www.erlang.org/doc/apps/kernel/logger_chapter.html#log-level\n" ). -spec warning(gleam@dict:dict(binary(), binary()), binary()) -> gleam@dict:dict(binary(), binary()). warning(Logger, Message) -> log(warning, gleam@dict:insert(Logger, <<"msg"/utf8>>, Message)), Logger. -file("src/glight.gleam", 75). ?DOC( " Log at the notice level. See the erlang log level documentation for \n" " more information and context.\n" " https://www.erlang.org/doc/apps/kernel/logger_chapter.html#log-level\n" ). -spec notice(gleam@dict:dict(binary(), binary()), binary()) -> gleam@dict:dict(binary(), binary()). notice(Logger, Message) -> log(notice, gleam@dict:insert(Logger, <<"msg"/utf8>>, Message)), Logger. -file("src/glight.gleam", 83). ?DOC( " Log at the info level. See the erlang log level documentation for \n" " more information and context.\n" " https://www.erlang.org/doc/apps/kernel/logger_chapter.html#log-level\n" ). -spec info(gleam@dict:dict(binary(), binary()), binary()) -> gleam@dict:dict(binary(), binary()). info(Logger, Message) -> log(info, gleam@dict:insert(Logger, <<"msg"/utf8>>, Message)), Logger. -file("src/glight.gleam", 91). ?DOC( " Log at the debug level. See the erlang log level documentation for \n" " more information and context.\n" " https://www.erlang.org/doc/apps/kernel/logger_chapter.html#log-level\n" ). -spec debug(gleam@dict:dict(binary(), binary()), binary()) -> gleam@dict:dict(binary(), binary()). debug(Logger, Message) -> log(debug, gleam@dict:insert(Logger, <<"msg"/utf8>>, Message)), Logger. -file("src/glight.gleam", 124). ?DOC(" Change the log visibility level to be output.\n"). -spec set_log_level(log_level()) -> nil. set_log_level(Level) -> glight_ffi:set_log_level(Level), nil. -file("src/glight.gleam", 134). ?DOC(" Change whether ANSI color is used in log output\n"). -spec set_is_color(boolean()) -> nil. set_is_color(Is_color) -> glight_ffi:set_is_color(Is_color), nil. -file("src/glight.gleam", 144). ?DOC(" Change the key used for the time in the log output.\n"). -spec set_json_time_key(binary()) -> nil. set_json_time_key(Key) -> glight_ffi:set_json_time_key(Key), nil. -file("src/glight.gleam", 154). ?DOC(" Change the key used for the message in the log output.\n"). -spec set_json_msg_key(binary()) -> nil. set_json_msg_key(Key) -> glight_ffi:set_json_msg_key(Key), nil. -file("src/glight.gleam", 164). ?DOC(" Change the key used for the level in the log output.\n"). -spec set_json_level_key(binary()) -> nil. set_json_level_key(Key) -> glight_ffi:set_json_level_key(Key), nil.