Module logi_layout

Log Message Layout Behaviour.

Copyright © 2014-2016 Takeru Ohta <phjgt308@gmail.com>

This module defines the logi_layout behaviour.
Required callback functions: format/4.

Description

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.

EXAMPLE

Usage example of a layout instance:
  > 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
  

Data Types

callback_module()

callback_module() = module()

A module that implements the logi_layout behaviour.

data()

data() = [term()]

A data which is subject to format

This type is an alias of the type of second arguemnt of the io_lib:format/2

extra_data()

extra_data() = term()

The value of the fourth arguemnt of the format/4 callback function.

If the layout() does not have an explicit extra_data(), undefined will be passed instead.

formatted_data()

formatted_data() = term()

Formatted Data

layout()

abstract datatype: layout(_FormattedData)

An instance of logi_layout behaviour implementation module.

layout()

layout() = layout(formatted_data())

An instance of logi_layout behaviour implementation module.

Function Index

format/4Returns an iodata() which represents Data formatted by Layout in accordance with Format and Context
get_extra_data/1Gets the extra data of Layout
get_module/1Gets the module of Layout
is_layout/1Returns true if X is a layout, false otherwise.
new/1Equivalent to new(Module, undefined).
new/2Creates a new layout instance.

Function Details

format/4

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/1

get_extra_data(Layout::layout()) -> extra_data()

Gets the extra data of Layout

get_module/1

get_module(Layout::layout()) -> callback_module()

Gets the module of Layout

is_layout/1

is_layout(X::layout() | term()) -> boolean()

Returns true if X is a layout, false otherwise

new/1

new(Module::callback_module()) -> layout()

Equivalent to new(Module, undefined).

new/2

new(Module::callback_module(), ExtraData::extra_data()) -> layout()

Creates a new layout instance


Generated by EDoc