Copyright © 2014-2016 Takeru Ohta <phjgt308@gmail.com>
Behaviours: logi_layout.
A built-in layout which formats log messages by an arbitrary user defined function
This layout formats log messages by format_fun/0
which was specified by the argument of new/1
.
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.
> error_logger:tty(false). % Suppresses annoying warning outputs for brevity
> Context = logi_context:new(sample_log, info).
> FormatFun = fun (_, Format, Data) -> io_lib:format("EXAMPLE: " ++ Format, Data) end.
> Layout = logi_builtin_layout_fun:new(FormatFun).
> lists:flatten(logi_layout:format(Context, "Hello ~s", ["World"], Layout)).
"EXAMPLE: Hello World"
A layout used by a sink can be specified at the time of installing the sink:
> Layout0 = logi_builtin_layout_fun:new(fun (_, Format, Data) -> io_lib:format("[LAYOUT_0] " ++ Format ++ "\n", Data) end).
> {ok, _} = logi_channel:install_sink(logi_builtin_sink_io_device:new(foo, [{layout, Layout0}]), info).
> logi:info("hello world").
[LAYOUT_0] hello world
> Layout1 = logi_builtin_layout_fun:new(fun (_, Format, Data) -> io_lib:format("[LAYOUT_1] " ++ Format ++ "\n", Data) end).
> {ok, _} = logi_channel:install_sink(logi_builtin_sink_io_device:new(bar, [{layout, Layout1}]), info).
> logi:info("hello world").
[LAYOUT_0] hello world
[LAYOUT_1] hello world
format_fun() = fun((logi_context:context(), io:format(), logi_layout:data()) -> logi_layout:formatted_data())
A log message formatting function
new/1 | Creates a layout which formats log messages by FormatFun |
new(FormatFun::format_fun()) -> logi_layout:layout()
Creates a layout which formats log messages by FormatFun
Generated by EDoc