concept SASL in category erlang

appears as: SASL
Erlang and OTP in Action

This is an excerpt from Manning's book Erlang and OTP in Action.

As you may know, SASL is also the name of a common framework for authentication in network protocols. But the SASL application in Erlang/OTP has absolutely nothing to do with that (it was named long before RFC 2222 was written). Here, it stands for System Architecture Support Libraries, and it’s one of the five basic applications that the rest of Erlang/OTP builds on (erts, kernel, stdlib, sasl, and compiler). It consists of a small collection of important services for system management.

We get back to SASL and gen_event later in this chapter; right now, we want to give you an overview of logging.

The server process comes up just fine, and 2 seconds later it terminates with some reasonably useful error information. Next, you’ll start SASL and see how things change.

The standard log messages—the ones you can write using the basic functions we showed you in section 7.1.3—are always available in any Erlang system. But applications can also define their own report types, which the system ignores unless an event handler has been added to act on them. SASL adds such a handler, which listens for reports sent by the standard OTP behaviours when supervisors start or restart a child process, if a child process dies unexpectedly, or if a behaviour-based process like a gen_server crashes. When you started SASL, you saw the main SASL supervisor starting some worker processes.

Let’s see what happens if you run the same example while SASL is running:

5> die_please:start_link().
{ok,<0.53.0>}
6>
=ERROR REPORT==== 4-Apr-2009::15:21:37 ===
** Generic server die_please terminating
** Last message in was timeout
** When Server state == {state}
** Reason for termination ==
** {{badmatch,right_now},
     [{die_please,handle_info,2},
      {gen_server,handle_msg,5},
      {proc_lib,init_p_do_apply,3}]}
6>
=CRASH REPORT==== 4-Apr-2009::15:21:37 ===
  crasher:
    initial call: die_please:init/1
    pid: <0.53.0>
    registered_name: die_please
    exception exit: {{badmatch,right_now},
                     [{die_please,handle_info,2},
                      {gen_server,handle_msg,5},
                      {proc_lib,init_p_do_apply,3}]}
      in function  gen_server:terminate/6
    ancestors: [<0.42.0>]
    messages: []
    links: [<0.42.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 377
    stack_size: 24
    reductions: 132
  neighbours:
    neighbour: [{pid,<0.42.0>},
                  {registered_name,[]},
                  {initial_call,{erlang,apply,2}},
                  {current_function,{shell,eval_loop,3}},
                  {ancestors,[]},
                  {messages,[]},
                  {links,[<0.27.0>,<0.53.0>]},
                  {dictionary,[]},
                  {trap_exit,false},
                  {status,waiting},
                  {heap_size,1597},
                  {stack_size,6},
                  {reductions,3347}]
** exception error: no match of right hand side value right_now
     in function  die_please:handle_info/2
     in call from gen_server:handle_msg/5
     in call from proc_lib:init_p_do_apply/3

You get the same error report as before, but you also get a crash report from SASL with a lot of additional information about the process that failed. This kind of information is useful when you’re debugging a crash in a live system.