View Source LogfmtEx (logfmt_ex v0.3.1)
A convenience for formatting logs in logfmt.
In logfmt, each line consists of a single level of key=value pairs, densely packed together.
For example:
Logger.info("I am a message", user_id: 123)
given the configuration
config :logger, :console,
format: {LogfmtEx, :format},
metadata: [:user_id, :pid, :file]
config :logfmt_ex, :opts,
message_key: "msg",
timestamp_key: "ts",
timestamp_format: :iso8601
would emit:
level=info msg="I am a message" ts="12:38:38.055 1973-03-12" user_id=123 pid=#PID<0.223.0> file=myapp/some_module.exs
The valid configuration parameters are:
:delimiter
- defaults to=
.:format
- A list of atoms that defines the order in which key/value pairs will written to the log line. Defaults to[:timestamp, :level, :message, :metadata]
. Valid parameters are:timestamp
- the timestamp of the log message:level
- the log level:message
- the log message itself:metadata
- metadata as key=value paris:node
- the node name
timestamp_key
- changes the key used for the timestamp field. Defaults totimestamp
.timestamp_format
- How the timestamp is formatted. Defaults to:elixir
. The options are:elixir
- Uses the same formatting functions found in the standard elixir log formatter. Example:"12:38:38.055 1973-03-12"
:epoch_seconds
- outputs an integer representing the number of seconds elapsed since January 1, 1970. Only useful for applications that emit logs sporadically.:iso8601
- Formats the timestamp according to ISO8601-2019. Example:2000-02-29T23:00:07
level_key
- the key used for the log level. Defaults tolevel
.message_key
- the key used for the message field. Defaults tomessage
, butmsg
is a popular alternative.
For encoding your own structs and types, see the LogfmtEx.ValueEncoder
protocol.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Link to this section Types
@type pattern() :: [pattern_keys()]
@type pattern_keys() :: :timestamp | :level | :message | :metadata | :node
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec format(Logger.level(), any(), Logger.Formatter.time(), Keyword.t()) :: iodata()
@spec format(Logger.level(), any(), Logger.Formatter.time(), Keyword.t(), Keyword.t()) :: iodata()