lily/logging
While the there is a logging package for Erlang, there isn’t one for JS, and since I’ve decided that the backend should also work on the JS target for some reason, this module is essentially a wrapper around the logging package for the Erlang target, alongside a JS version that aims to provide the exact same results.
See logging for more information, it’s
the same hex package (the same logger used by mist and wisp) so log
lines work cleanly with framework logs. On JavaScript, log lines are
written to console.error / console.warn / console.info /
console.debug by level, along with the colours used for the Erlang
package. This works identically in browsers, Node, Bun, and Deno.
On Erlang, configure installs the logging package’s formatter and
set_level sets the minimum level. On JavaScript, configure is a no-op
and set_level maintains a programmatic level filter.
import lily/logging
pub fn main() {
logging.configure()
logging.set_level(logging.Info)
logging.info("server ready")
logging.auto_info(SomeMessage("hello")) // logs "INFO SomeMessage(\"hello\")"
}
Types
Values
pub fn auto_alert(value: a) -> Nil
Inspect value with string.inspect and log the result at Alert level.
pub fn auto_critical(value: a) -> Nil
Inspect value with string.inspect and log the result at Critical
level.
pub fn auto_debug(value: a) -> Nil
Inspect value with string.inspect and log the result at Debug level.
pub fn auto_emergency(value: a) -> Nil
Inspect value with string.inspect and log the result at Emergency
level.
pub fn auto_error(value: a) -> Nil
Inspect value with string.inspect and log the result at Error level.
pub fn auto_info(value: a) -> Nil
Inspect value with string.inspect and log the result at Info level.
This is probably used the most.
server.on_message(srv, fn(msg, _model, _client_id) {
logging.auto_info(msg) // e.g. logs "INFO AddTodo(\"milk\")"
})
pub fn auto_log(level: Level, value: a) -> Nil
Inspect value with string.inspect and log the result at the given level.
pub fn auto_notice(value: a) -> Nil
Inspect value with string.inspect and log the result at Notice level.
pub fn auto_warning(value: a) -> Nil
Inspect value with string.inspect and log the result at Warning level.
pub fn configure() -> Nil
Configure the default logger. On Erlang, this installs the logging
package’s pretty formatter and sets the level to Info. On JavaScript,
this is a no-op — the console is always ready.
pub fn set_level(level: Level) -> Nil
Set the minimum level of log messages to emit. Messages below this level are suppressed.
On Erlang, delegates to logger:set_primary_config. On JavaScript,
maintains a module-level threshold — useful on Node/Bun/Deno servers where
DevTools is not available.