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

Dear perlmonks,

I use TimingBotDBI in a daemon, but otherwise in a very similar fashion as in the example. In the article it says that a commit is only necessary if Mysql AutoCommit is off. I make a connection with the Mysql database in another module like so:

my $dbh = DBI->connect($dsn,$user,$pass,{RaiseError => 0, AutoCommit = +> 1, $driver eq 'mysql' ? (mysql_enable_utf8 => 1) : (), });

So, AutoCommit is on.

I pass the database handler around as a reference and part of a larger session object, so the log handler and database handler are easy accessible everywhere.

I noticed that I have to call a commit to the TimingBotDBI object or otherwise nothing gets saved in the database. I think it's the DBI modules that throws this warning:

commit ineffective with AutoCommit enabled at /usr/local/share/perl/5.10.0/XML/RSS/TimingBotDBI.pm line 83.

This is because the commit function in TimingBot does a commit on the database handler. Of course this is not a big problem. But I'm curious: Could I do this in a more elegant way and avoid this warning?

And I have a second question. I use Log4perl. The warning is printed to the command line. Is it possible to print it to my log handler? Or is this impossible as ikegami suggests in his final paragraph here: http://www.perlmonks.org/?node_id=688741#688764

I create my log like this as a method of my session. I attempt to print to the log when the code is run as a daemon and to the command line when it's run on the command line, like so:

sub log { my $self = shift; my $output = shift; unless ( exists $self->{ _log } ) { Log::Log4perl->init( $self->getRoot( "/etc/log.conf" ) ); my $log = Log::Log4perl->get_logger( $0 ); if ( defined $log ) { $self->{ _log } = $log; } } unless( $self->{ _daemonize } ) { my $log2cmdline = Slurper::Log->new(); $self->{ _log } = $log2cmdline; } return $self->{ _log }; }

And I tried to redirect the STDERR like so:

open STDERR, '>>', $session->log->debug;

Any insight as into how to do a better job is greatly appreciated.

Kind regards,
Arjan.

Moved from thread Perl RSS aggregator by Arunbear

Replies are listed 'Best First'.
Re: Perl RSS aggregator
by arjan (Initiate) on Mar 26, 2010 at 22:27 UTC

    Meanwhile I've found both the answers.

    The reason for the error is a bug in TimingBotDBI, that says in the commit subroutine $dbh->commit. Users that have made a connection with mysql with AutoCommit on, will get an error.

    It should say:

    $dbh->commit if  $dbh->{'AutoCommit'} == 0;

    So a commit is only done if the user has a mysql connection with autocommit off. (I've emailed the author)


    The answer to the second question is: via IO Layers, like http://search.cpan.org/~akaplan/PerlIO-via-Logger-1.01/lib/PerlIO/via/Logger.pm

    This post pointed me in the right direction: http://www.mail-archive.com/log4perl-devel@lists.sourceforge.net/msg00107.html

    Kind regards,
    Arjan.

    P.S. Somehow my post was moved, by Arunbear, why?

      P.S. Somehow my post was moved, by Arunbear, why?

      Thread crapping.

        The article is about TimingBotDBI. I asked about strange behaviour of TimingBotDBI and later identified a bug in TimingBotDBI. That doesn't seem like crapping to me. That's handy for the next reader of the article.

        But thanx for the info, I couldn't have guessed.