View Source LogfmtEx.ValueEncoder protocol (logfmt_ex v0.4.0)

Protocol for encoding data types.

Example:

defmodule User do
  defstruct [:email, :name, :id]

  defimpl LogfmtEx.ValueEncoder do
    def encode(user), do: to_string(user.id)
  end
end

If there is no protocol for a data type passed as metadata, then encoding will fall back to the String.Chars protocol. If that protocol isn't specified either, the formatter will fall back to Kernel.inspect/1.

Note that the algebra documents produced by Kernel.inspect/1 don't lend themselves to logfmt - this fallback is provided to minimize the chance that the formatter fails, instead making a "best effort" at producing usable output. It is recommended to implement either the LogfmtEx.ValueEncoder or String.Chars protocol for any data types that might find their way into your logs.

Link to this section Summary

Link to this section Types

Link to this section Functions

@spec encode(term()) :: iodata()