When I run my tests, I get a :undef to 500 response
if a method do not exist. This does not happen when I run in dev, and I am pretty sure it is something I have done with some configs at some point. The problem is that I can’t understand where or how, and it is starting to get annoying.
My configs for logger in config.exs is:
# Our Logger application configuration (affects all logging)
config :logger,
backends: [
:console
],
compile_time_purge_matching: [
[level_lower_than: :info]
]
# Our Console Backend-specific configuration
config :logger, :console,
format: {AppName.LogFormatter, :format},
metadata: [:request_id, :crash_reason, :user_id],
level: :debug
In test.exs
config :logger, level: :info
And my LogFormatter
def format(level, message, timestamp, metadata) do
"##### #{format_timestamp(timestamp, level)} #{format_metadata(metadata)} [#{level}] #{
message
}\n"
rescue
_ -> "Could not format message: #{inspect({level, message, timestamp, metadata})}\n"
end
defp format_timestamp({{_year, _month, _date}, {hh, mm, ss, _ms}}, :debug) do
Integer.to_string(hh) <> ":" <> Integer.to_string(mm) <> ":" <> Integer.to_string(ss)
end
defp format_timestamp({{year, month, date}, {hh, mm, ss, ms}}, _level) do
%DateTime{
year: year,
month: month,
day: date,
zone_abbr: "UTC",
hour: hh,
minute: mm,
second: ss,
microsecond: {ms, 0},
utc_offset: 0,
std_offset: 0,
time_zone: "Etc/UTC"
}
|> DateTime.to_string()
end
defp format_metadata(metadata) do
metadata
|> output_file_and_line
end
defp output_file_and_line(metadata) do
case {Keyword.get(metadata, :file), Keyword.get(metadata, :line)} do
{nil, nil} -> ""
{file, line} -> file <> ":" <> Integer.to_string(line)
end
end
Any help would be greatly appreciated!