[erlang-questions] Line numbers for logging/errors.

Richard Kelsall r.kelsall@REDACTED
Wed Mar 12 16:08:53 CET 2008


Nohl Attila Rajmund wrote:
> Yes, erlang has excellent trace facilities, it shows me that the 'rfmm'
> function was called - unfortunately it doesn't show that which of the 10
> rfmm functions was called. 

Breaking a small subject off the main thread. I haven't written much
Erlang yet so maybe I'm just missing something, but I get the impression
Erlang won't tell me the line number when something goes wrong. I feel
it would be useful to know this and very in keeping with the Erlang
approach of making bugs nice and visible. So my vote while we're all
requesting changes to Erlang :) is for more line number visibility.

On a related subject I've played around with the LINE macro to tag
my own logging/error messages with line numbers and the best I could
produce was something like this :

   -define(log(Line, Message, Var), log_message(?MODULE, Line, Message,
           ??Var, Var)).  % LINE macro always gives '1' if I put it here.

   log_message(Module, Line, Message, VarName, Var) ->
      io:format("log: {~p, ~p} ~s ~s = ~p~n", [Module, Line, Message,
                VarName, Var]).

and then in my code I can do things like

     ?log(?LINE, "Unexpected post", Other),

This works fine, but it would be nice to just write

     ?log("Unexpected post", Other),

and get the line number somehow. Can this be done?


Richard.




More information about the erlang-questions mailing list