Hi, The code works but the issue is even after I add appender file in my module.pm , it is logging only once until it is returned from the subrouting in the module. After that , whatever logging I put, it is appended to only the file , which I appended in script . Below is the code : test.pl -------
use warnings; use strict; use Log::Log4perl qw(:easy); use TestModule; my $log_file = "GIVE SOME PATH"; my %key_value_pairs = ( "log4perl.rootLogger" => "DEBUG, Logfile,TestModule,Screen", "log4perl.appender.Logfile" => "Log::Log4perl::Appender::File", "log4perl.appender.Logfile.mode" => "clobber", "log4perl.appender.Logfile.filename" => "$log_file", "log4perl.appender.Logfile.layout"=> "Log::Log4perl::Layout::Patte +rnLayout", "log4perl.appender.Logfile.layout.ConversionPattern" => "%d %p %C: +%L> %m%n", "log4perl.appender.TestModule" => "Log::Log4perl::Appender::Fi +le", "log4perl.appender.TestModule.mode" => "clobber", "log4perl.appender.TestModule.filename" => "$log_file", "log4perl.appender.TestModule.layout"=> "Log::Log4perl::Layout +::PatternLayout", "log4perl.appender.TestModule.layout.ConversionPattern" => "%d %p +%C:%L> %m%n", "log4perl.appender.Screen" => "Log::Log4perl::Appender::Screen", "log4perl.appender.Screen.layout" => "Log::Log4perl::Layout::Patte +rnLayout", "log4perl.appender.Screen.layout.ConversionPattern" => "%d %p %C: +%L> %m%n", ); Log::Log4perl::init(\%key_value_pairs); my $testmodule = TestModule->new( "key" => "value", ); INFO "Creating object for testmodule"; $testmodule->_printTime();
module.pm ---------
package TestModule; use Log::Log4perl qw(:easy); use strict; use warnings; sub new { my ($this,%params) = @_; my $args = { "arg1" => "5", "arg2" => "6", %params, }; bless($args,$this); my $log_file = "somepath"; my $new_log_file = "GIVE SOME PATH"; my $file_appender = Log::Log4perl::Appender->new( "Log::Log4perl::Appender::File", name => "TestModule", filename => "$new_log_file"); INFO "New object created"; return $args; } sub _printTime { my $time = localtime; INFO "$time"; } 1;

Actually , I need both the files to be updated once a new appender is added.


In reply to Re^3: Log4Perl across modules by rbala
in thread Log4Perl across modules by rbala

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.