Support pretty printing records found in a module at compile time #100

Merged
merged 2 commits into from Dec 12, 2012

3 participants

@Vagabond

The lager parse transform now stores all record definitions found at compile time in the module's attributes and, using lager:pr/2, they can be prettyprinted as part of the log message:

lager:info("My state is ~p", [lager:pr(State, ?MODULE)])

Gives:

00:16:37.888 [info] My state is #state{lions=[simba],tigers=[tigger],bears=[winnie,yogi],oh_my=true}

Needs more tests, but this is a proof of concept. Both records local to the module and records imported from a .hrl file are supported, so if the record is resolvable at compile time, it will be included in the module attributes.

@reiddraper @seancribbs

@seancribbs

This is why you are the awesomest. 🍻 Also, bonus points for making your parse transform and test easy to follow (and passing!).

@joedevivo joedevivo commented on the diff Dec 12, 2012
src/lager_transform.erl
walk_ast([], AST).
walk_ast(Acc, []) ->
- lists:reverse(Acc);
+ insert_record_attribute(Acc);
@joedevivo
joedevivo added a line comment Dec 12, 2012

Does this not need to be reversed anymore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@joedevivo

This totally works!

11> m:log_record().                            
12:26:37.374 [info] State #state{one=1,two=2,three=3}
ok

+1 to merge, although I'd still like to know what happened to that reverse

@Vagabond

The reverse is done as part of the traverse done in the insert_record_attribute function.

@joedevivo

Works for me, +1 to merge

@Vagabond Vagabond merged commit 2b51f7b into master Dec 12, 2012

1 check passed

Details default The Travis build passed
@rzezeski rzezeski referenced this pull request in basho/yokozuna Mar 15, 2013
Closed

Use lager:pr once riak moves to lager 2.0 #75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment