<div dir="ltr">I would suggest using a hook system, where you can register hooks (funs) at important points in the code. That way you can provide means to do both logging and instrumentation. Something like:<div><br></div><div>library:add_hook(pre_request, fun(Request) -></div><div> leg:dbg("request: ~p~n", [Request]),</div><div> folsom_metrics:notify(requests, {inc, 1})</div><div>end).</div><div><br></div><div>Be careful with any performance impacts this might have though.</div><div><br></div><div>-cvik</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jan 11, 2016 at 2:07 PM Chandru <<a href="mailto:chandrashekhar.mullaparthi@gmail.com">chandrashekhar.mullaparthi@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Have a log function such as this inside your library code.<div><br></div><div>log_msg(Fmt, Args) -></div><div> log_msg(application:get_env(my_library, logging_mf), Fmt, Args).</div><div><br></div><div>log_msg({ok, {Mod, Fun}}, Fmt, Args) when is_atom(Mod), is_atom(Fun) -></div><div> catch apply(Mod, Fun, [Fmt, Args]);</div><div>log_msg(_, _, _) -></div><div> ok.</div><div><br></div><div>That way, the user can control how the messages get logged.</div><div><br></div><div>cheers,</div><div>Chandru</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 11 January 2016 at 07:34, Max Lapshin <span dir="ltr"><<a href="mailto:max.lapshin@gmail.com" target="_blank">max.lapshin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi.<div><br></div><div>As we know, it is good when library doesn't have any hardcoded dependencies at all.<br></div><div><br></div><div>I don't understand what is a good way to remove lager (or any other logging library) from library dependencies.</div><div><br></div><div><br></div><div>For example, we have an mpegts decoder/encoder library. This library takes binary and unpacks it to list of frames or packs back:</div><div><br></div><div>mpegts_decoder:decode(Binary, mpegts_decoder:init(Options)) -> {ok, Frames, State}</div><div><br></div><div><br></div><div>There are calls to lager in some places of code that are used for indicating some statuses:</div><div><div><br></div><div>dump_psi(Decoder, NewPMT),</div></div><div>lager:info("PMT: ~p", [Descriptors]),<br></div><div>...</div><div><br></div><div><br></div><div>What is the proper way to refuse from adding logger as a dependency for such pure library?</div><div>Pass a callback into initialisation options?</div><div><br></div><div><br></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>