deadpickle has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to add a log file using Log4perl to a final script. I'm packaging the script using perl2exe and when I go to run the file I get the error:
undefined value provided for log level at PERL2EXE_STORAGE/Log/Log4perl/Appender .pm line 77
Not sure where the error is happening. Here is the logger code:
use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($ERROR); my $logger = get_logger(); # Appenders my $appender = Log::Log4perl::Appender->new( "Log::Dispatch::File", filename => "grruvi.log", mode => 'trunc' ); $logger->add_appender($appender); # Layouts my $layout = Log::Log4perl::Layout::PatternLayout->new("%d %p> %F{1}:% +L %M - %m%n"); $appender->layout($layout); my $timer_log = Glib::Timeout->add(100, \&log); sub log { if (defined $!){ if (length $! != 0 and length $! <= 30){ # $log->error($!) $logger->error($!); } } }
I really just want to log errors or maybe even warnings so that I can handle them later. I'm sure there is better code out there than what I have. thanks for the help!

Replies are listed 'Best First'.
Re: Adding a Log to a perl2exe file
by bruno (Friar) on Aug 20, 2008 at 05:07 UTC
    For what I've heard, perl2exe's use is deprecated.
    You sould try the PAR module (PAR module, which comes with a packing application, "pp").

    Read this for more information.

      true but, I have had trouble trying to package GTK2 programs using pp in the past. Has that changed?
Re: Adding a Log to a perl2exe file
by saintmike (Vicar) on Aug 20, 2008 at 17:03 UTC
    Are you sure that the script runs from the command line at all, without using perl2exe? Couple of things to watch out for:

    First, I wouldn't recommend naming a function "log()", since log is a built-in. Use a different name and run the script from the command line to make sure nothing else is causing a problem.

    Secondly, you probably need to tell perl2exe that you're using Log::Dispatch::File, as it's probably not smart enough to tell that by looking at the code, since you're not "use"ing it but letting Log4perl require it at runtime.

    Thirdly, I would recommend using Log4perl's native file appender (comes with Log4perl), Log::Log4perl::Appender::File.

    Fourthly, there's nothing wrong with your configuration, but you probably want to use a Log4perl configuration file (or string!) to keep things nice and clean and in one place.

Re: Adding a Log to a perl2exe file
by Anonymous Monk on Aug 20, 2008 at 04:31 UTC