I recently did a deep dive into ExUnit.CaptureLog and found that it (mostly) reverted to the default formatter with no way to specify an alternative formatter such as LoggerJSON to be able to test certain advanced features like the LoggerJSON.Redactor protocol to ensure that fields logged are properly redacted.
The (mostly) is because at work we have a formatter that's a variation of the default formatter and we (mostly) get the output that we expect (the default formatter drops any metadata that isn't a scalar; our custom formatter does best-effort serialization), but we didn't find a way to provide an entirely alternative formatter like LoggerJSON. So I copied the relevant files from the Elixir source code and created CaptureLogger. https://hexdocs.pm/capture_logger/CaptureLogger.html The core change is in the call handler for `:log_capture_on`: ```elixir {formatter, opts} = Keyword.pop(opts, :formatter, Application.get_env(:capture_logger, :formatter)) {formatter_mod, formatter_config} = case formatter do {_, _} -> formatter nil -> Logger.default_formatter(opts) module when is_atom(module) -> module.new(opts) end ``` I'd be happy to contribute a similar change for future versions of Elixir, but CaptureLogger will work nicely for earlier versions until this gets released. WDYT? -a -- Austin Ziegler • [email protected] • [email protected] http://www.halostatue.ca/ • http://twitter.com/halostatue -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/elixir-lang-core/CAJ4ekQu33Bk9955ZCvmsyLChq3OKm2hH0pwcTHDwA14ckd0umg%40mail.gmail.com.
