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

Richard Kelsall r.kelsall@REDACTED
Thu Mar 13 14:58:09 CET 2008


Gah, indeed it does work, more egg on face :) I went through several
versions to get to that point, I must have tried substituting ?LINE
into a previous version and failed somehow. Thank you.

Richard.


Hynek Vychodil wrote:
> May be I missed some, but it works for me in R11B-5
> 
> -module(temp).
> -export([test/0]).
> -define(log(Message, Var), log_message(?MODULE, ?LINE, Message, ??Var, 
> Var)).
> 
> 
> 
> log_message(Module, Line, Message, VarName, Var) ->
>      io:format("log: {~p, ~p} ~s ~s = ~p~n", [Module, Line, Message,
>                VarName, Var]).
> 
> test() ->
>     X = {a,b},
>     ?log("Unexpected post", X). % here is line 20
> 
> %end
> 
> $ erl -smp
> Erlang (BEAM) emulator version 5.5.5 [source] [smp:1] [async-threads:0] 
> [hipe] [kernel-poll:false]
> 
> Eshell V5.5.5  (abort with ^G)
> 1> c(temp).
> {ok,temp}
> 2> temp:test().
> log: {temp, 20} Unexpected post X = {a,b}
> ok
> 3>
> 
> 
> On Wed, Mar 12, 2008 at 4:08 PM, Richard Kelsall 
> <r.kelsall@REDACTED <mailto:r.kelsall@REDACTED>> wrote:
> 
>     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.
> 
> 
> -- 
> --Hynek (Pichi) Vychodil



More information about the erlang-questions mailing list