instrument_log_exporter_console (instrument v1.0.0)

View Source

Console exporter for log records.

Exports log records to stdout or stderr for debugging and development.

Example Usage

  %% Register with default options
  instrument_log_exporter:register(instrument_log_exporter_console:new()),
 
  %% Register with options
  instrument_log_exporter:register(instrument_log_exporter_console:new(#{
      format => json,      %% json | text (default: text)
      output => standard_io %% standard_io | standard_error
  })),

Text Format

  [2026-03-31T12:00:00Z] INFO [trace_id=abc span_id=xyz] User logged in {"user":"john"}

JSON Format (OTLP-compatible)

  {"timestamp":"...","severityText":"INFO","body":"User logged in",...}

Summary

Functions

Exports log records to the console.

Forces a flush (no-op for console).

Initializes the exporter.

Shuts down the exporter.

Creates a new console log exporter configuration with defaults.

Creates a new console log exporter configuration.

Functions

exporter_export(LogRecords, State)

-spec exporter_export([#log_record{timestamp :: integer() | undefined,
                                   observed_timestamp :: integer() | undefined,
                                   severity_number :: integer() | undefined,
                                   severity_text :: binary() | undefined,
                                   body :: term(),
                                   attributes :: map(),
                                   trace_id :: <<_:128>> | undefined,
                                   span_id :: <<_:64>> | undefined,
                                   trace_flags :: 0 | 1 | undefined,
                                   resource ::
                                       #resource{attributes :: map(),
                                                 schema_url :: binary() | undefined} |
                                       undefined,
                                   scope ::
                                       #scope{name :: binary(),
                                              version :: binary() | undefined,
                                              attributes :: map(),
                                              schema_url :: binary() | undefined} |
                                       undefined}],
                      #state{format :: text | json, output :: standard_io | standard_error}) ->
                         {ok, #state{format :: text | json, output :: standard_io | standard_error}} |
                         {error,
                          term(),
                          #state{format :: text | json, output :: standard_io | standard_error}}.

Exports log records to the console.

exporter_force_flush(State)

-spec exporter_force_flush(#state{format :: text | json, output :: standard_io | standard_error}) ->
                              {ok,
                               #state{format :: text | json, output :: standard_io | standard_error}}.

Forces a flush (no-op for console).

exporter_init(Config)

-spec exporter_init(map()) ->
                       {ok, #state{format :: text | json, output :: standard_io | standard_error}} |
                       {error, term()}.

Initializes the exporter.

exporter_shutdown(State)

-spec exporter_shutdown(#state{format :: text | json, output :: standard_io | standard_error}) -> ok.

Shuts down the exporter.

new()

-spec new() -> #{module := module(), config := map()}.

Creates a new console log exporter configuration with defaults.

new(Config)

-spec new(map()) -> #{module := module(), config := map()}.

Creates a new console log exporter configuration.