View Source StructuredLogger.ValueMapper protocol (StructuredLogger v0.0.1)

As part of the log processing pipeline we transform metadata values to ensure we create a flat structure while still keeping important information around.

This Protocol is responsible for the mapping.

Link to this section Summary

Functions

For each value it can either return

Link to this section Types

@type complex() ::
  %{required(atom() | binary()) => primitive()}
  | [{atom() | binary(), primitive()}]
@type primitive() :: atom() | binary() | integer() | pid() | reference()
@type t() :: term()

Link to this section Functions

@spec map(term()) :: {:ok, primitive() | complex()} | :ignore

For each value it can either return

  • {:ok, term()}
  • :ignore

If :ignore is returned, the value is removed. If {:ok, term()} is returned, it will depend on the type of the term returned:

For atom(), binary(), integer(), pid() and reference() it won't change anything

For a keyword list or a map, it will generate derived metadata using . as a separator

For example, for a metadata data with key :req and a value that ValueMapper implementation returns %{method: "GET", path: "/posts"}, it will generate "req.method" => "GET" and "req.method" => "/posts".

Nesting is not allowed, this is just a helper for simple cases like the one shown above.

default-implementation

Default implementation

binary(), atom(), number(), pid(), reference(), Date, DateTime, NaiveDateTime, Time and URI are all kept since these are values that can easily be serialized into a simple format.

exceptions

Exceptions

By default exceptions (any structure with __exception__: true) are converted to:

%{ type: ExceptionType, message: "Exception Message" }

Where ExceptionType is the module and "Exception Message" is the Exception.message/1 result.