Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Greetings monks

UPDATE:I have create a new attribute to the Daemon class to hold the logger reference from the gimme_logger sub. After that, I recovered the logger from the object instance attribute, but when reaching the DEMOLISH method, the logger attribute was set automatically to undef, finishing the process without any warning (but without the log messages as well).

I'm using Log::Log4perl to log messages for two Moose classes that I have.

These two classes have each other their own appender:

log4perl.logger.Siebel.Srvrmgr.Daemon=DEBUG, A1 log4perl.appender.A1=Log::Log4perl::Appender::File log4perl.appender.A1.filename=C:/Temp/perl/project.log log4perl.appender.A1.stderr=0 log4perl.appender.A1.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.A1.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m% +n log4perl.appender.A2= Log::Log4perl::Appender::Screen log4perl.appender.A2.stderr=0 log4perl.appender.A2.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.A2.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m% +n log4perl.logger.Siebel.Srvrmgr.ListParser=WARN, A2

Only the Daemon uses a file as appender.

I've created the following class method to retrieve a single instance of the logger:

sub gimme_logger { my $cfg = Siebel::Srvrmgr->logging_cfg(); die "Could not start logging facilities" unless ( Log::Log4perl->init_once( \$cfg ) ); return Log::Log4perl->get_logger('Siebel::Srvrmgr::Daemon'); }

That's how I'm invoking the logger inside each method:

sub run { my $self = shift; my $logger = __PACKAGE__->gimme_logger(); weaken($logger); # rest of code goes here


sub DEMOLISH { my $self = shift; my $logger = __PACKAGE__->gimme_logger(); weaken($logger); # rest of code goes here

And this is the method invoked to retrieve the loggers configuration:

sub logging_cfg { my $cfg = undef; local $/; if ( $ENV{SIEBEL_SRVRMGR_DEBUG} ) { if ( ( -e $ENV{SIEBEL_SRVRMGR_DEBUG} ) and ( -f $ENV{SIEBEL_SRVRMGR_DEBUG} ) ) { open( my $in, '<', $ENV{SIEBEL_SRVRMGR_DEBUG} ) or die "Cannot read $ENV{SIEBEL_SRVRMGR_DEBUG}: $!"; $cfg = <$in>; close($in); } else { die 'ENV SIEBEL_SRVRMGR_DEBUG is defined but the value does not exists in +the filesystem or is not a file'; } } else { $cfg = <Siebel::Srvrmgr::DATA>; } return $cfg; }

When I terminated the application, I'm getting the following messages in the CMD.exe prompt:

C:\Temp\memcached> Starting Nagios::Cache::Server...done Starting RPC::XML::Server...done Ready to accept requests close() on unopened filehandle FH at C:/strawberry/perl/site/lib/Log/L +og4perl/Appender/ line 257 during global destruction. Can't close C:/Temp/perl/project.log (Bad file descriptor) at C:/straw +berry/perl/site/lib/Log/Log4perl/Appender/ line 282 during glo +bal destruction.

I'm having trouble finding out why Log::Log4perl is trying to close the appender twice, since:

  1. I'm using a single instance of logger
  2. The instance should be eliminated at the end of the method due weaken from Scalar::Utils
  3. Only the Daemon logger is using the file appender
  4. I'm not passing references of the logger outside the methods scope

Initially I was using a global scalar (declared with our) to have a single logger for the whole package, but when reaching the DEMOLISH method the object reference was not available anymore.

I'm using Strawberry perl 5.16.3 with Log::Log4perl version 1.42 in a Windows 7 box.

Alceu Rodrigues de Freitas Junior
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

In reply to Getting "close() on unopened filehandle FH" from Log::Log4perl by glasswalk3r

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (6)
    As of 2018-06-22 06:03 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (121 votes). Check out past polls.