Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: RFC: A simple and badly-named logging module

by xdg (Monsignor)
on Feb 18, 2006 at 01:47 UTC ( #531108=note: print w/replies, xml ) Need Help??

in reply to RFC: A simple and badly-named logging module

My first impression is that it's a nice little utility!

My second impression is that I'd like to see something a little more like a unix syslog instead of the 0, 1, 2 constants. E.g. set a destination for all events of a given level or better, choose different files for different types.

use Log ( trace => "everything.log", info => "info_or_better.log", info => \STDERR, # also echo info or higher to STDERR )

I'm not so sure that's really the way I'd want it, but maybe it will give you some ideas.

Finally, I would definitely not use globals like $Log::filename or $Log::info. Consider storing these in a hash keyed on the caller's package. This will allow modular programs to use your module differently in different parts of the program.


Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^2: RFC: A simple and badly-named logging module
by radiantmatrix (Parson) on Feb 22, 2006 at 18:03 UTC

    I'd love to use constants instead of 0/1/2, but since I'm doing configuration during import, the constants wouldn't be available during the configuration. I could accept string values, something like:

    use Log ( warn => 'BOTH', info => 'LOG', debug => 'QUIET' );

    In this particular case, I don't think the 0/1/2 division is all that unintuitive. At its core, it's boolean: should I log warnings? yes=>1, no=>0. I admit the '2' is more of a stretch, but considering any mode set to 2 logs to 2 places (STDERR and logfile), I don't think it's very far-fetched. So, I'm undecided about that one.

    Your other suggestions are all good, but they suggest, to me, that you'd want one of the already-existing log modules rather than this one.

    For syslog-style logging, if you need or want that, you're better off with one of the existing log modules anyhow (like Sys::Syslog or the mother of them all, Log::Log4Perl), so I'm not sure it's worth the work to implement properly.

    The globals suggestion is interesting, but I'm worried about a functionality trade. One of the original reasons for the decision I made was to easily allow configuration of logging for the entire application in one place. I can see the argument for letting modules log differently, but I can't grok how to do that while still allowing the choice of how it works today. That is, all modules simply use Log, and the calling program does the configuration.

    Besides, when I need that level of control, I'm probably already in the realm of wanting all that Log::Log4Perl provides anyhow, so I'd move to that point. Unless I'm missing something? I'd be open to suggestions on how I could have it both ways, in which case it would go on my todo list.

    A collection of thoughts and links from the minds of geeks
    The Code that can be seen is not the true Code
    I haven't found a problem yet that can't be solved by a well-placed trebuchet

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://531108]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2020-02-25 22:19 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (113 votes). Check out past polls.