Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^3: Import constants?

by almut (Canon)
on Aug 05, 2010 at 08:37 UTC ( [id://853063] : note . print w/replies, xml ) Need Help??

in reply to Re^2: Import constants?
in thread Import constants?

Try something like

use DBIx::Log4perl qw(:masks); $DBIx::Log4perl::LogMask = DBIX_L4P_LOG_OUTPUT | DBIX_L4P_LOG_INPUT;

The values of the constants represent individual bits being set, i.e.

(binary) DBIX_L4P_LOG_INPUT 1 00000001 DBIX_L4P_LOG_OUTPUT 2 00000010

Each bit activates a certain functionality. You can combine them using bitwise or (|), e.g.

00000001 00000010 -------- 00000011

The resulting value has all bits set which were set in any of the or'ed input values.

Replies are listed 'Best First'.
Re^4: Import constants?
by BrowserUk (Patriarch) on Aug 05, 2010 at 08:52 UTC


    use DBIx::Log4perl qw(:masks); my $dbh = DBIx::Log4perl->connect(...); $dnh->dbix_l4p_setattr( 'dbix_l4p_logmask', DBIX_L4P_LOG_TXN | DBIC_L4P_LOG_CONNECT | DBIX_L4P_LOG_INPUT | DBIX_L4P_LOG_ERRCAPTURE | DBIX_L4P_LOG_ERRORS | DBIX_L4P_LOG_DBDSPECIFIC ); ...

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Unfortunately it didn't do any difference.

      I'm doing the following:
      use Log::Log4perl; use DBIx::Log4perl qw(:masks); Log::Log4perl->init("myconfigfile.cfg"); $dbh = DBIx::Log4perl->connect($DSN, "user", "pass"); $dbh->dbix_l4p_setattr( 'dbix_l4p_logmask', DBIX_L4P_LOG_TXN | DBIC_L4P_LOG_CONNECT | DBIX_L4P_LOG_INPUT | DBIX_L4P_LOG_ERRCAPTURE | DBIX_L4P_LOG_ERRORS | DBIX_L4P_LOG_DBDSPECIFIC ); ...
      Maybe my problem is related to my usage of the config file?
        it didn't do any difference

        The set of masks I posted is the default set as described in the first entry in the pod.

        If you want the setting to be different, you'll have to choose which constants you want, and change the code to suit.

Re^4: Import constants?
by DreamT (Pilgrim) on Aug 05, 2010 at 08:49 UTC
    I get
    Can't locate auto/DBIx/Log4perl/st/ in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at /usr/local/share/perl/5.10.0/DBIx/Log4perl/ line 281
    when running it, so mayme i'm missing something?

      Could you show the exact code that produces the problem?

      With the following test I can't replicate the issue:

      #!/usr/bin/perl -l use DBIx::Log4perl qw(:masks); $DBIx::Log4perl::LogMask = DBIX_L4P_LOG_OUTPUT | DBIX_L4P_LOG_INPUT; print $DBIx::Log4perl::LogMask;

      (prints '3', as expected)

        I used:
        use DBIx::Log4perl qw(:masks); $DBIx::Log4perl::LogMask = DBIX_L4P_LOG_OUTPUT | DBIX_L4P_LOG_INPUT; Log::Log4perl->init("myconfig.cfg"); $dbh = DBIx::Log4perl->connect($DSN, "user", "pass");
        log4perl.logger = FATAL, LOGFILE log4perl.appender.LOGFILE=Log::Log4perl::Appender::File log4perl.appender.LOGFILE.filename=logs/FATAL.TXT log4perl.appender.LOGFILE.mode=append log4perl.appender.LOGFILE.Threshold = ERROR log4perl.appender.LOGFILE.layout=PatternLayout log4perl.appender.LOGFILE.layout.ConversionPattern=[%r] %F %L %c - %m% +n log4perl.logger.DBIx.Log4perl=DEBUG, A1 log4perl.appender.A1=Log::Log4perl::Appender::File log4perl.appender.A1.filename=logs/OK.txt log4perl.appender.A1.mode=append log4perl.appender.A1.layout=Log::Log4perl::Layout::SimpleLayout

      From a quick look at the code, I would say try replacing line 277 in DBIx/Log4perl/

      $sth->_dbix_l4p_perl(2, # line 277 sub {Data::Dumper->Dump( [$res], ["fetchrow_hashref($h->{dbh_no}.$sth->{private_DBIx_st_no} +)"])}) if ($h->{logmask} & DBIX_L4P_LOG_OUTPUT);


      $sth->_dbix_l4p_debug($h, 2, # line 277 ...

      AFAICT, there is no method _dbix_l4p_perl in any of the related packages (while there are similarly named ones like ..._debug, ..._info, etc.).  No guarantees, though (untested).

        ...and of course it worked:-) Thanks a lot!
        Should I file a bug report to the author about this?

      That was a bug in DBIx::Log4perl and is fixed in 0.22 which I've just uploaded. I didn't see your thread even though I am a perl monk because your subject did not grab me and I don't have time to read every one - perhaps there is a lesson to be learnt there. The fix correctly identified elsewhere in this thread is trivial and a little embarrassing although I have to admit to not using the OUTPUT logging in my own projects.

        The subject did start out as something else - I wanted to learn how to use constants:) But I can see that v0.22 works "from scratch" after installing it on a new machine.