quixadhal has asked for the wisdom of the Perl Monks concerning the following question:
My naive through was to pass a coderef in as the warp_message parameter, hoping I could just have it do the sprintf conversion to flatten things into a single argument that would become the last bound parameter passed...$log->info("Data directory: %s", $options->{'dir'});
and then...my $spr = sub { my $fmt = shift; return sprintf $fmt, @_; };
This resulted in the unfortunate Can't use string ("Can't use string ("Data director"...) as a HASH ref while "strict refs" in use at /usr/local/share/perl/5.14.2/Log/Log4perl/Appender.pm line 281. I also have loggers to the screen and file, but the DBI one is the problem child, and while he's having a tantrum, the others don't even get to run. Obviously, things would work fine if I used sprintf myself at the caller level, but that defeats the purpose of having a nice clean logging statement. Any suggestions?my $conf = qq! log4perl.rootLogger = TRACE, DBAppndr log4perl.appender.DBAppndr = Log::Log4perl::Appender::DBI log4perl.appender.DBAppndr.datasource = $dsn log4perl.appender.DBAppndr.username = $db_user log4perl.appender.DBAppndr.password = $db_passwd log4perl.appender.DBAppndr.sql = INSERT INTO log (level, ti +mestamp, method, line, message) VALUES (?,?,?,?,?) log4perl.appender.DBAppndr.params.1 = %p log4perl.appender.DBAppndr.params.2 = %d{yyyy-MM-dd HH:mm:ss.SSS +} log4perl.appender.DBAppndr.params.3 = %M log4perl.appender.DBAppndr.params.4 = %L log4perl.appender.DBAppndr.usePreparedStmt = 1 log4perl.appender.DBAppndr.layout = Log::Log4perl::Layou +t::NoopLayout log4perl.appender.DBAppndr.warp_message = $spr !; Log::Log4perl::init( \$conf );
|
|---|