logi_ex v0.1.1 Logi.BuiltIn.Layout.Fun
A built-in layout which formats log messages by an arbitrary user defined function.
Behaviours: Logi.Layout
.
This layout formats log messages by format_fun/0
which was specified by the argument of new/1
.
Note
This module is provided for debuging/testing purposes only.
A layout will be stored into a logi_channel’s ETS.
Then it will be loaded every time a log message is issued.
Therefore if the format function (format_fun/0
) of the layout is a huge size anonymous function,
all log issuers which use the channel will have to pay a non negligible cost to load it.
Examples
iex> layout0 = Logi.BuiltIn.Layout.Fun.new(fn (_, format, data) -> :io_lib.format("[LAYOUT_0] " <> format <> "\n", data) end)
iex> {:ok, _} = Logi.Channel.install_sink(Logi.BuiltIn.Sink.IoDevice.new(:foo, [layout: layout0]), :info)
iex> Logi.info "hello world"
#OUTPUT# [LAYOUT_0] hello world
iex> layout1 = Logi.BuiltIn.Layout.Fun.new(fn (_, format, data) -> :io_lib.format("[LAYOUT_1] " <> format <> "\n", data) end)
iex> {:ok, _} = Logi.Channel.install_sink(Logi.BuiltIn.Sink.IoDevice.new(:bar, [layout: layout1]), :info)
iex> Logi.info "hello world"
#OUTPUT# [LAYOUT_1] hello world
#OUTPUT# [LAYOUT_0] hello world
Summary
Types
A log message formatting function
Functions
Creates a layout which formats log messages by format_fun
Types
format_fun()
format_fun() :: (Logi.Context.context, :io.format, Logi.Layout.data -> Logi.Layout.formatted_data)
A log message formatting function.
Functions
Creates a layout which formats log messages by format_fun
.