[erlang-questions] lager/io:format and sets

Ola Bäckström Ola.Backstrom@REDACTED
Tue Nov 11 09:33:40 CET 2014

I would not recommend to change the internal representation just for making pretty printing simpler.

I'd either make a private conversion function, or if this concerns an otp genserver implement the gen_server optional behaviour format_status/2.
You'd have to do the conversion of the State yourself, and then call the function every time you want to log the state.
The advantage of making the conversion in the format_status/2 function is that also crash reports will contain converted state.
Perhaps also in other tools too, like observer, I haven't tried.


-----Original Message-----
From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Cian Synnott
Sent: den 11 november 2014 02:14
To: Oleg Tsarev
Cc: erlang-questions@REDACTED
Subject: Re: [erlang-questions] lager/io:format and sets

>On Tue, Nov 11, 2014 at 12:02 AM, Oleg Tsarev <oleg@REDACTED> wrote:
>> How I can fix the output of the set in lager and io:format?
>I don't see a "built in" way to fix this. To roll your own, you could "patch over" the record with sets:to_list/1 to make a printable version. E.g. something like
>printable(#state{channel_id_set=Set}=State) ->
>  State#state{channel_id_set=sets:to_list(Set)}.
>lager:debug("args ~p, state ~p", [Args, lager:pr(printable(State), ?MODULE)),
>It's not super. You might need to change the record's type annotations to avoid upsetting Dialyzer.

More information about the erlang-questions mailing list