instrument_log_exporter_file (instrument v1.0.0)
View SourceFile exporter for log records with rotation support.
Exports log records to a file with optional rotation based on file size.
Example Usage
%% Register with required path
instrument_log_exporter:register(instrument_log_exporter_file:new(#{
path => "/var/log/app.log"
})),
%% Register with options
instrument_log_exporter:register(instrument_log_exporter_file:new(#{
path => "/var/log/app.log",
format => json, %% text | json (default: text)
max_size => 10485760, %% 10MB (default, 0 = unlimited)
max_files => 5, %% number of rotated files (default: 5)
compress => true %% compress rotated files (default: false)
})),File Rotation
When max_size is reached, files rotate:
app.log -> app.log.1 -> app.log.2 -> ... -> app.log.NIf compress=true, rotated files become app.log.1.gz, etc.
Summary
Functions
Exports log records to the file.
Forces a flush.
Initializes the exporter.
Shuts down the exporter.
Creates a new file log exporter configuration.
Functions
-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{path :: binary(), format :: text | json, max_size :: non_neg_integer(), max_files :: pos_integer(), compress :: boolean(), fd :: file:io_device() | undefined, current_size :: non_neg_integer()}) -> {ok, #state{path :: binary(), format :: text | json, max_size :: non_neg_integer(), max_files :: pos_integer(), compress :: boolean(), fd :: file:io_device() | undefined, current_size :: non_neg_integer()}} | {error, term(), #state{path :: binary(), format :: text | json, max_size :: non_neg_integer(), max_files :: pos_integer(), compress :: boolean(), fd :: file:io_device() | undefined, current_size :: non_neg_integer()}}.
Exports log records to the file.
-spec exporter_force_flush(#state{path :: binary(), format :: text | json, max_size :: non_neg_integer(), max_files :: pos_integer(), compress :: boolean(), fd :: file:io_device() | undefined, current_size :: non_neg_integer()}) -> {ok, #state{path :: binary(), format :: text | json, max_size :: non_neg_integer(), max_files :: pos_integer(), compress :: boolean(), fd :: file:io_device() | undefined, current_size :: non_neg_integer()}}.
Forces a flush.
-spec exporter_init(map()) -> {ok, #state{path :: binary(), format :: text | json, max_size :: non_neg_integer(), max_files :: pos_integer(), compress :: boolean(), fd :: file:io_device() | undefined, current_size :: non_neg_integer()}} | {error, term()}.
Initializes the exporter.
-spec exporter_shutdown(#state{path :: binary(), format :: text | json, max_size :: non_neg_integer(), max_files :: pos_integer(), compress :: boolean(), fd :: file:io_device() | undefined, current_size :: non_neg_integer()}) -> ok.
Shuts down the exporter.
Creates a new file log exporter configuration.