gen_event:add_sup_handler... correct usage?

Steve Davis steven.charles.davis@REDACTED
Tue Jul 28 12:18:08 CEST 2009


Hi,

I have boot-time logging for a server that needs to start before
anything really happens, i.e. **before the main supervisor is kicked
off by application:start(my_server)**. Despite this requirement, I
still need the error_logger process to supervise my gen_event handler.
I have read and re-read the docs (and the error_logger/gen_event
source code), but I am still not 100% clear or indeed happy that I'm
doing the right thing wrt to OTP principles.

I've implemented it by doing the following...

==== summarized for clarity =====
%% my_server_sup
% note... this module manages both app and sup callbacks
-behaviour(application).
-behaviour(supervisor).
....
start(_Type, Args) ->
    my_logger_h:start_link(),
    ....
    case lists:member(my_logger, gen_event:which_handlers
(error_logger)) of
        true ->
           supervisor:start_link({local, ?MODULE}, ?MODULE, Args);
       _ ->
           io:format(user, "FATAL: Boot logger failed to initialize.",
[]),
           {error, boot_log_init}
    end.

%% my_logger_h
-behaviour(gen_event).
....
start_link() ->
    ....various init stuff
    gen_event:add_sup_handler(error_logger, ?MODULE, {LogId, LogPath,
Rollover}).
======end=====

...while all of this "works", I have concerns about the OTP-ness of
doing this, and also a nagging feeling that the fact that application
process is essentially the "supervisor" that's passed to error_logger,
not the supervisor process itself.

I was hoping for any advice/comment from those with more experience as
I'm still learning decent OTP design.

Regards and TIA,
Steve


More information about the erlang-questions mailing list