Packages
logger_json
7.0.4
7.0.4
7.0.3
7.0.2
7.0.1
7.0.0
6.2.1
6.2.0
6.0.3
6.0.2
6.0.1
6.0.0
6.0.0-rc.4
6.0.0-rc.3
6.0.0-rc.2
6.0.0-rc.1
6.0.0-rc.0
5.1.4
5.1.3
5.1.2
5.1.1
5.1.0
5.0.0
4.3.0
4.2.0
4.1.0
4.0.0
3.3.0
3.2.0
3.1.2
3.1.1
3.1.0
3.0.3
3.0.2
3.0.1
3.0.0
2.0.1
2.0.0
1.3.0
1.2.1
1.2.0
1.1.0
1.0.1
1.0.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
This package includes a set of :logger formatters designed to output logs in JSON format. It is compatible with a variety of log management systems that support JSON, including Google Cloud Logging and Error Reporting, Datadog, ElasticSearch, LogStash, FileBeat, and Kibana.
Current section
Files
Jump to
Current section
Files
lib/logger_json/formatter/message.ex
defmodule LoggerJSON.Formatter.Message do
@moduledoc false
# crash
def format_message({:string, message}, %{crash_reason: crash_reason}, %{crash: crash_fmt}) do
crash_fmt.(message, crash_reason)
end
# binary
def format_message({:string, message}, _meta, %{binary: binary_fmt}) do
binary_fmt.(message)
end
# OTP report or structured logging data
def format_message(
{:report, data},
%{report_cb: callback} = meta,
%{binary: binary_fmt, structured: structured_fmt} = formatters
) do
cond do
is_function(callback, 1) and callback != (&:logger.format_otp_report/1) ->
format_message(callback.(data), meta, formatters)
is_function(callback, 2) ->
callback.(data, %{depth: :unlimited, chars_limit: :unlimited, single_line: false})
|> binary_fmt.()
true ->
structured_fmt.(data)
end
end
def format_message({:report, data}, _meta, %{structured: structured_fmt}) do
structured_fmt.(data)
end
def format_message({format, args}, _meta, %{binary: binary_fmt}) do
format
|> Logger.Utils.scan_inspect(args, :infinity)
|> :io_lib.build_text()
|> binary_fmt.()
end
end