[erlang-questions] Architecture question: logging inside library

Mark Allen mrallen1@REDACTED
Mon Jan 11 17:51:00 CET 2016


Macros is the approach we've used in some places (basho_bench) for example.  But a lot of these other suggestions are good. :) 

    On Monday, January 11, 2016 2:40 AM, Dmitry Kolesnikov <dmkolesnikov@REDACTED> wrote:
 

 Hello,

I am using macro to wrap logger library. 
This gives me a freedom to config desired library and behavior at build time.  


-ifndef(EMERGENCY).
-define(EMERGENCY(Fmt, Args), lager:emergency(Fmt, Args)).
-endif.

-ifndef(ALERT).
-define(ALERT(Fmt, Args), lager:alert(Fmt, Args)).
-endif.

-ifndef(CRITICAL).
-define(CRITICAL(Fmt, Args), lager:critical(Fmt, Args)).
-endif.

-ifndef(ERROR).
-define(ERROR(Fmt, Args), lager:error(Fmt, Args)).
-endif.

-ifndef(WARNING).
-define(WARNING(Fmt, Args), lager:warning(Fmt, Args)).
-endif.

-ifndef(NOTICE).
-define(NOTICE(Fmt, Args), lager:notice(Fmt, Args)).
-endif.

-ifndef(INFO).
-define(INFO(Fmt, Args), lager:info(Fmt, Args)).
-endif.

-ifdef(CONFIG_DEBUG).
  -define(DEBUG(Str, Args), lager:debug(Str, Args)).
-else.
  -define(DEBUG(Str, Args), ok).
-endif.


Best Regards,
Dmitry


> On Jan 11, 2016, at 9:34 AM, Max Lapshin <max.lapshin@REDACTED> wrote:
> 
> Hi.
> 
> As we know, it is good when library doesn't have any hardcoded dependencies at all.
> 
> I don't understand what is a good way to remove lager (or any other logging library) from library dependencies.
> 
> 
> For example, we have an mpegts decoder/encoder library. This library takes binary and unpacks it to list of frames or packs back:
> 
> mpegts_decoder:decode(Binary,  mpegts_decoder:init(Options)) ->  {ok, Frames, State}
> 
> 
> There are calls to lager in some places of code that are used for indicating some statuses:
> 
> dump_psi(Decoder, NewPMT),
> lager:info("PMT: ~p", [Descriptors]),
> ...
> 
> 
> What is the proper way to refuse from adding logger as a dependency for such pure library?
> Pass a callback into  initialisation options?
> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions


  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160111/91611d4b/attachment.htm>


More information about the erlang-questions mailing list