On Mon, 4 Aug 2008, Curt Tilmes wrote:
> I attended your talk at OSCON about Log4perl (which I enjoyed
> immensely, thank you!),
Hi Curt,
thanks, glad you liked it ;).
> and asked a question about command line options rather than config
> files. I've thought about it a bit since then, and put together the
> attached module.
This is fantastic, I've always wanted something like that.
I have one suggestion: Since -d or -v are used by some scripts for
different purposes, how about letting the script determine which options
are covered? In this way,
use Log::Log4perl::CommandLine qw(:all);
would activate all available command line options, while
use Log::Log4perl::CommandLine qw(v q d);
would activate -v, -q, and -d.
And, sure, feel free to use Log::Log4perl::CommandLine as the name, that
makes perfect sense.
Is it OK if I forward your post to the log4perl devel list?
Thanks for your Log4perl extension!
-- Mike
Mike Schilli
[EMAIL PROTECTED]
> replace the configuration file interface (which is infinitely more
> configurable), but rather to make an easy way to 1) make use of
> Log4perl even if you don't want to think about the config files (or
> teach end users how to write them), and 2) provide an easy command
> line way to override a couple parts without continually editing/saving
> a new config file.
>
> What do you think about the proposed module name:
> Log::Log4perl::CommandLine
>
> As implemented, I just call Getopt::Long to do all the command line
> option parsing,
> but I know you don't want to add dependencies on external modules for your
> core
> Log4perl module. This could be released independently if that was a concern.
>
> To illustrate, I took the simple "drink soda" script from one of your
> tutorial articles
> and changed it like this:
> =================================
> use Log::Log4perl qw(:easy);
> use Log::Log4perl::CommandLine;
>
> drink();
> drink("Soda");
>
> sub drink {
> my($what) = @_;
>
> my $logger = get_logger();
>
> if(defined $what) {
> $logger->info("Drinking ", $what);
> } else {
> $logger->error("No drink defined");
> }
> }
> ==================================
>
> Now it is command line enabled, and you can do things like this:
>
> % perl log.pl
> 2008/08/04 15:55:53 No drink defined
>
> % perl log.pl -v (or --verbose)
> 2008/08/04 15:55:56 No drink defined
> 2008/08/04 15:55:56 Drinking Soda
>
> % perl log.pl -q (or --quiet)
>
> % perl log.pl --debug --logfile log.txt
> 2008/08/04 16:08:16 No drink defined
> 2008/08/04 16:08:16 Drinking Soda
>
> % cat log.txt
> 2008/08/04 16:08:16 No drink defined
> 2008/08/04 16:08:16 Drinking Soda
>
> % perl log.pl --trace My::Module
> [...]
>
> What do you think?
>
> Curt
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
log4perl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/log4perl-devel