[erlang-questions] Line numbers for logging/errors.
Richard Kelsall
r.kelsall@REDACTED
Wed Mar 12 18:44:06 CET 2008
Thank you. That looks good. I'll experiment with it.
Eider Silva de Oliveira wrote:
> I use this:
>
> -define(d(Format, Args),
> io:format("~s" ++ Format,
> [string:left(lists:flatten(io_lib:format("~p~p(~p):", [self(),?MODULE,
> ?LINE])), 35, $ ) | Args])).
>
>
> On 12/03/2008, at 12:08, Richard Kelsall 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?
>>
More information about the erlang-questions
mailing list