in reply to Re: Log::Log4perl and singleton design issue
in thread Log::Log4perl and singleton design issue
I don't know what cool features of L4P you would be losing if you do this, so someone beat me with a cluestick if needed.
Whenever I want to use a public module but I don't like it's semantics, I write a module to change it to be more friendly. Sometimes this is making a non-OO module behave in an OO fashion, sometimes it is merely changing the API of the object involved, and in a few cases it is turning an OO module into a non OO module. I think this is what you want here.
sub log_it { Log::Log4Perl->logger('section') ->log(shift); }
For instance, if you had a module that exported log_it, you could make sure it calls Log::Log4Perl->init('file.conf') (in BEGIN maybe?) and so make sure that it is always called. Boom, you get your oneliners back.
Plus, you also get shorter call symantics - log_it('my_log_message') is a lot friendlier then Log::Log4Perl->logger('section')->log('my_log_message), but then of course it is the code that is actually run by log_it and so does the same thing with less typing.
|
|---|