I have a large project consisting of cron jobs and cgis that do some screen scrapes. Life became unmanagebale - cutting, pasting, and dying over and over again. I finally turned to OOP. I barely know my $self, but it is beautiful. Wait till I discover my inheritance.

I'm now turning to Log4perl and log4perl conf files to clean up my mess of "print 'foo' if's," and rewriting my .pl's and .cgi's to use my module 'EZ::Emulate.pm.' I want Emulate.pm's logging behavior to be determined by the Log4perl conf file of the program calling on Emulate.pm.

I currently have it working with this in main:

my $log_conf = './log.fifo.conf'; use Log::Log4perl qw(get_logger :levels); Log::Log4perl->init("$log_conf"); our $logger = get_logger(); $logger->info('Foo');
and in Emulate.pm with:

$main::logger->info('Bar');

However, having the name of a main package variable hard coded in the module just feels... dirty.

Should I instead be doing something like this in main:

use EZ::Emulate; $EZ::Emulate::log_conf = $log_conf;
and then in Emulate.pm use "use Log4perl" and create loggers in the EZ::Emulate namespace, or should I be approaching this differently?

I'd really rather do this right the second time instead of the third, and I'm not sure that I'm not missing something simple here. Any suggestions?

Thanks,

Queeg


In reply to Log4perl with my module by queeg

Title:
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, details, 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, summary, 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.