# vim: ts=2 sw=2 et ft=org
#+STYLE: <LINK href="../stylesheet.css" rel="stylesheet" type="text/css" />
#+TITLE: Log Handler
#+AUTHOR: Jesse Gumm (@jessegumm)
#+OPTIONS:   H:2 num:1 toc:1 \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+EMAIL: 

#+TEXT: [[file:../index.org][Getting Started]] | [[file:../api.org][API]] | [[file:../elements.org][Elements]] | [[file:../actions.org][Actions]] | [[file:../validators.org][Validators]] | [[file:../handlers.org][*Handlers*]] | [[file:../config.org][Configuration Options]] | [[file:../about.org][About]]

* Log Handler

  The Log Handler tells Nitrogen what to do with the =wf:error=, =wf:warning=,
  and =wf:info= messages. It does not currently affect how Erlang errors are
  handled. It only affects how error messages are handled when generated by the
  above function calls.

** Behavior Functions
 
**** =init(Config, State)=

  Initialize the handler

  + /Return Value/ - ={ok, NewState}= 

**** =finish(Config, State)=

  Clean up the handler

  + /Return Value/ - ={ok, NewState}=
  
**** =info(Message, Config, State)=
  
  Generate an info message

  + =Message= - The string to generate the message

  + /Return Value/ - Description of the return value

**** =warning(Message, Config, State)=
  
  Generate a warning message

  + =Message= - The string to generate the message

  + /Return Value/ - Description of the return value

**** =error(Message, Config, State)=
  
  Generate an error message

  + =Message= - The string to generate the message

  + /Return Value/ - Description of the return value

** Example

Here is the complete text of the default log handler in Nitrogen, which
basically serves as a pass-through for the basic Erlang error_logger module.

#+BEGIN_SRC erlang

-module (default_log_handler).
-behaviour (log_handler).
-export ([
    init/2,
    finish/2,
    info/3,
    warning/3,
    error/3
]).

init(_Config, State) ->
    {ok, State}.

finish(_Config, State) ->
    {ok, State}.

info(S, _Config, State) ->
    error_logger:info_msg([S, "\n"]),
    {ok, State}.

warning(S, _Config, State) ->
    error_logger:warning_msg([S, "\n"]),
    {ok, State}.

error(S, _Config, State) ->
    error_logger:error_msg([S, "\n"]),
    {ok, State}.

#+END_SRC


** See Also

  + [[../handlers.html][Handler Overview]]

  + [[../api.html#sec-14][API: Logging]]
