Dear Monks

I have been using Log::Log4perl in my project for the past one month and I'm happy
with the module

Lately I am merging some of my database operations from various Perl scripts into a single module
and because of this I'm facing an issue with Logging, for which I seek your valuable advice

Below is current working setup:

* Different Perl scripts, parsing and loading data into the DB and logging into
there own log files (script1, logs into script1.yyyy-mm-dd.log and script2 logs into script2.yyyy-mm-dd.log and so on)

In the new setup, I have pulled the insertion part from the above two scripts into
one single utility module. The module has two different methods (load_script1, load_script2)
Currently the script is creating a single log file called test_log.yyyy-mm-dd.log
I want my script to still create two different logfiles instead of a single log file for the above two methods as in my
previous working setup . Below is my code
##test_log.pl #!/usr/bin/perl use strict; use warnings; Log::Log4perl::init_once("$ENV{CONF_PATH}" . "/log4perl.conf" ); sub get_log{ use POSIX qw(strftime); my $now_string = strftime("%Y-%m-%d", localtime); my $log = sprintf "%s.$now_string.info.log", basename( $0 ); return "$ENV{LOG_PATH}" . '/'. $log; } use Loader; Loader::load_script1(); Loader::load_script2(); __END__; ##Loader.pm package Loader; use strict; use warnings; sub load_script1 { my ($log) = Log::Log4perl::get_logger("SCRIPT1"); $log->info("inside script2 method"); } sub load_Script2 { my ($log) = Log::Log4perl::get_logger("SCRIPT2"); $log->info("inside script2 method"); } 1; ##log4perl.conf [log4perl] log4perl.logger=INFO,Logfile,Screen log4perl.appender.Logfile = Log::Log4perl::Appender::File log4perl.appender.Logfile.filename = sub { return get_log(); } log4perl.appender.Logfile.mode = append log4perl.appender.Logfile.additivity =0 log4perl.appender.Logfile.layout = Log::Log4perl::Layout::PatternLayou +t log4perl.appender.Logfile.layout.ConversionPattern = %d %p> %m%n [Modules level setup] log4perl.logger.main = INFO log4perl.logger.script = INFO log4perl.logger.ABC.SCRIPT1= INFO log4perl.logger.ABC.SCRIPT2= INFO

In reply to Creating different logfiles for different methods using Log::Log4perl by Anonymous Monk

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.