Skip to content

Instantly share code, notes, and snippets.

@qezz
Last active August 15, 2025 12:36
Show Gist options
  • Select an option

  • Save qezz/9542aa98ce51a4e0418e338af87ae82a to your computer and use it in GitHub Desktop.

Select an option

Save qezz/9542aa98ce51a4e0418e338af87ae82a to your computer and use it in GitHub Desktop.
Wrapped Gleam logger (which is a wrapper for the Erlang logger)

Original posting: lpil/logging#7 (comment)

Put

  • main.gleam to src/, or use it in your own entrypoint.
  • wrapped_logging_ffi.erl to src/

Then things should work. Run as

$ gleam run

It will produce the following output (the "INFO" will be colored; if you want uncolored, update the flag in the wrapper)

2025-08-15T11:29:03Z INFO Hello, Joe!
import gleam/erlang/process
import logging.{Info}
pub fn main() {
logger_configure()
logging.log(Info, "Hello, Joe!")
process.sleep(100)
}
@external(erlang, "wrapped_logging_ffi", "configure")
pub fn logger_configure() -> Nil
-module(wrapped_logging_ffi).
-export([configure/0, format/2]).
format(LogEvent, Config) ->
Timestamp = calendar:system_time_to_rfc3339(erlang:system_time(second), [{unit, second}, {offset, "Z"}]),
LogEventWithMeta = LogEvent#{meta => #{}},
ExistingOutput = logging_ffi:format(LogEventWithMeta, Config),
ActualString = case ExistingOutput of
{string, Str} -> Str;
Other -> Other
end,
iolist_to_binary([Timestamp, " ", ActualString]).
configure() ->
logging_ffi:configure(),
logger:update_handler_config(default, #{
formatter => {wrapped_logging_ffi, #{colored => true}}
}),
nil.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment