[erlang-questions] how: logging messages to another node
Serge Aleynikov
saleyn@REDACTED
Thu Nov 1 13:37:51 CET 2007
Hmm, seems like this is what you want to do:
rpc:call(Node, erlang, whereis, [error_logger]).
on the other hand as Uffe said you can propagate the error reports to
other (e.g. backend) nodes. In the LAMA jungerl contrib (which's a bit
outdated, as I haven't had time to upload the latest version) there's an
event handler that has similar functionality. The idea is to use macros
in your code to report an error locally or broadcast it to error_loggers
on known nodes (code is stripped from lama/include/logger.hrl and
lama/src/lama_syslog_h.erl):
-define(ERROR(Str_, Args_),
error_logger:error_report({lama,error}, {false, {Str_, Args_}})).
-define(DIST_ERROR(Str_, Args_),
error_logger:error_report({lama,error}, {true, {Str_, Args_}})).
And have an error handler that would do something along the line of what
LAMA does in the distribute/2 function:
handle_event({error_report, GL, {Pid, {lama,Type}, {Distr,Report}}},
State) ->
% Send distributed messages to other nodes, and also if the
% Type is in [warning,error] forward it other gen_event handlers or
% print [info,debug] messages to screen
distribute(Distr, {error_report, GL, {Pid,{lama,Type},Report}}, State),
{ok, State};
distribute(false = _Distr, {_, _GL, {_Pid, {_,Type},_Rep}} = Report,
State) ->
distribute2(Type, Report, State);
distribute(true, {_, _GL, {_Pid, {_,Type},_Rep}} = Report, State) ->
% Make sure the other nodes don't drop this message
DistRep = setelement(2, Report, lama),
_ = [gen_event:notify({error_logger, N}, DistRep) || N <-
nodes()],
distribute2(Type, Report, State).
Serge
Jay Nelson wrote:
> I am working on a scenario with diskless nodes talking to a back end
> node with a disk. I want to forward error_logger messages to the
> backend node. Here is the chain of events:
>
> 1) Start the diskless node
> a) installs an event_handler to capture error_logger messages
> b) messages are queued up until the backend node connects
> 2) Start the backend node
> 3) Detect node up and forward messages to backend
>
> I could put a server on the backend node and forward messages to it,
> but it seemed that there should be a way to leverage the existing
> error_logger. My first attempts were trying to get the process id of
> the error_logger on another node, but there was no way to do this
> that I could find. I could monitor that process using {error_logger,
> Node} but I couldn't figure out a way to remotely obtain the
> process_id. Is there a way?
>
> I have a working version now, which feels a bit of a hack to me which
> works as follows:
>
> Backend machine:
> - global:register_name(logger, whereis(error_logger)).
>
> Diskless machine:
> - Pid = global:whereis_name(logger),
> - group_leader(Pid, self()),
> - error_logger:error_report(Msg)
>
> Voila, the message appears on the backend node. I don't like the
> idea of using the group_leader / error_logger approach or the magic
> 'logger' global name. It seems there should be an easier way to
> reach out to the remote error_logger process, especially since I can
> monitor it using the {RegName, Node}, but I can't find any other
> functions for discovering the process_id.
>
> Any suggestions for an alternate approach?
>
> jay
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list