0

I have a .conf file which has

log4perl.appender.logFile          = Log::Log4perl::Appender::File
log4perl.appender.logFile.filename = /myapp/conf/<ENVTAG>myapp.conf

Then, the Perl script consumes it:

Log::Log4perl::init($logConf);
my $logger = Log::Log4perl->get_logger;
$logger->info("Begin");
$logger->info("End");

I'd like to know how to read/change/replace the <'ENVTAG'> token in order to set it to: "dev", "prod", "testing" in the Perl application (regex here?)... Also, how can I edit the "logfile.filename" in the Perl application?

Thanks.

user3772839
  • 265
  • 3
  • 11

1 Answers1

0

Found this one on perlmonks web site

You can reference it in a config or in to program itself.

my $logconf = qq(
     log4perl.logger                        = DEBUG , LOG, SCREEN

    log4perl.appender.LOG               = Log::Log4perl::Appender::File
    log4perl.appender.LOG.filename      = sub { return getLogFile(); }
    log4perl.appender.LOG.mode          = clobber
    log4perl.appender.LOG.autoflush     = 1
    log4perl.appender.LOG.layout        = Log::Log4perl::Layout::PatternLayout
    log4perl.appender.LOG.layout.ConversionPattern = %d %p %m %n
);


sub getLogFile {

    my $log=$0; 
    $log =~ s/^.*\\//; 
    $log =~ s/\..*//; 
    $log .= ".log";

    return $log;
}