Repository: elixir-lang/elixir

Issue #9814: Logger crashing when logging sasl metadata
Created: 2020-02-12T11:34:53Z
Environment

Elixir & Erlang/OTP versions (elixir --version):

Erlang/OTP 22 [erts-10.6.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]

Elixir 1.10.1 (compiled with Erlang/OTP 22)


Operating system: macOS 10.14.6 (18G3020)

Current behavior
When starting https://github.com/syfgkjasdkn/logger-crash/tree/60f92ad442e5fb775c0ae5e4e21ae2658888ba65 with
config :logger, :console, metadata: :all

config :logger,
  handle_otp_reports: true,
  handle_sasl_reports: true
the logger application crashes
:gen_event handler Logger.Backends.Console installed in Logger terminating
** (exit) an exception was raised:
    ** (Protocol.UndefinedError) protocol String.Chars not implemented for %{tag: :info_report, type: :progress} of type Map. This protocol is implemented for the following type(s): Float, DateTime, Time, List, Version.Requirement, Atom, Integer, Version, Date, BitString, NaiveDateTime, URI
        (elixir 1.10.1) lib/string/chars.ex:3: String.Chars.impl_for!/1
        (elixir 1.10.1) lib/string/chars.ex:22: String.Chars.to_string/1
        (logger 1.10.1) lib/logger/formatter.ex:180: Logger.Formatter.metadata/1
        (logger 1.10.1) lib/logger/formatter.ex:180: Logger.Formatter.metadata/1
        (logger 1.10.1) lib/logger/formatter.ex:152: anonymous fn/6 in Logger.Formatter.format/5
        (elixir 1.10.1) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
        (logger 1.10.1) lib/logger/formatter.ex:151: Logger.Formatter.format/5
        (logger 1.10.1) lib/logger/backends/console.ex:186: Logger.Backends.Console.format_event/5
=INFO REPORT==== 12-Feb-2020::11:30:19.745968 ===
    application: logger
    exited: shutdown
    type: temporary

with metadata being
[
  domain: [:otp, :sasl],
  error_logger: %{tag: :info_report, type: :progress},
  file: "supervisor.erl",
  function: "report_progress/2", 
  gl: #PID<0.200.0>,
  line: 1419,
  logger_formatter: %{title: 'PROGRESS REPORT'},
  mfa: {:supervisor, :report_progress, 2},
  module: :supervisor,
  pid: #PID<0.205.0>,
  report_cb: &:logger.format_otp_report/1,
  time: 1581508122898762
]
Expected behavior
Maps in metadata should be logged. Possible format (similar to https://github.com/ferd/flatlog):
... error_logger_tag=info_report error_logger_type=progress ...

Or maybe a note about metadata: :all not always working for the console backend would be enough.

Duplicate issue #8507: ExUnit.CaptureLog.remove_capture fails with error
Created: 2018-12-11T13:54:01Z
Environment
Erlang/OTP 21 [erts-10.0.7] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.7.3 (compiled with Erlang/OTP 21)

Current behavior
I changed this line:
ExUnit.start()
to
ExUnit.start(capture_log: true)
in order to silence log output during tests. However, some tests are now failing with this error message:
     ** (EXIT from #PID<0.1226.0>) exited in: ExUnit.CaptureLog.remove_capture(#PID<0.1241.0>)
         ** (EXIT) {:error, :module_not_found}

Any ideas?

Closing comment (2020-02-14T09:54:20Z): Thanks, I was able to reproduce it. It is related to #9814 and it has been fixed on master and v1.10 branch. We will release v1.10.2 in a week with the fix.