Copyright © 2014-2016 Takeru Ohta <phjgt308@gmail.com>
This module defines the logi_layout behaviour.
Required callback functions: format/4.
Log Message Layout Behaviour
This module defines the standard interface to format log messages issued by logi
functions
(e.g. logi:info/3
, logi:warning/3
, etc).
A layout instance may be installed into a channel along with an associated sink.
> error_logger:tty(false). % Suppresses annoying warning outputs for brevity
> Context = logi_context:new(sample_log, info).
> FormatFun = fun (_, Format, Data) -> lists:flatten(io_lib:format("EXAMPLE: " ++ Format, Data)) end.
> Layout = logi_builtin_layout_fun:new(FormatFun).
> logi_layout:format(Context, "Hello ~s", ["World"], Layout).
"EXAMPLE: Hello World"
A more realistic example:
> FormatFun = fun (_, Format, Data) -> lists:flatten(io_lib:format("EXAMPLE: " ++ Format ++ "\n", Data)) end.
> Layout = logi_builtin_layout_fun:new(FormatFun).
> {ok, _} = logi_channel:install_sink(logi_builtin_sink_io_device:new(foo, [{layout, Layout}]), info).
> logi:info("hello world").
EXAMPLE: hello world
callback_module() = module()
A module that implements the logi_layout
behaviour.
data() = [term()]
A data which is subject to format
This type is an alias of the type of second arguemnt of theio_lib:format/2
extra_data() = term()
The value of the fourth arguemnt of the format/4
callback function.
layout()
does not have an explicit extra_data()
, undefined
will be passed instead.
formatted_data() = term()
Formatted Data
abstract datatype: layout(_FormattedData)
An instance of logi_layout
behaviour implementation module.
layout() = layout(formatted_data())
An instance of logi_layout
behaviour implementation module.
format/4 | Returns an iodata() which represents Data formatted by Layout in accordance with Format and Context |
get_extra_data/1 | Gets the extra data of Layout |
get_module/1 | Gets the module of Layout |
is_layout/1 | Returns true if X is a layout, false otherwise. |
new/1 | Equivalent to new(Module, undefined). |
new/2 | Creates a new layout instance. |
format(Context::logi_context:context(), Format::io:format(), Data::data(), Layout) -> FormattedData
Returns an iodata()
which represents Data
formatted by Layout
in accordance with Format
and Context
get_extra_data(Layout::layout()) -> extra_data()
Gets the extra data of Layout
get_module(Layout::layout()) -> callback_module()
Gets the module of Layout
is_layout(X::layout() | term()) -> boolean()
Returns true
if X
is a layout, false
otherwise
new(Module::callback_module()) -> layout()
Equivalent to new(Module, undefined).
new(Module::callback_module(), ExtraData::extra_data()) -> layout()
Creates a new layout instance
Generated by EDoc