From: <jsc...@gm...> - 2007-03-10 22:17:25
|
Thanks for you fast answer! but I dont understand. I have read the FAQ : 'What if I need dynamic values in a static Log4perl=20 configuration file?' but I thought this solution with=20 perl.appender.FileApp.filename =3D sub { "$0.log" } is just for defining a dynamic name for the log file at initialization phas= e=20 of Log4perl (only once in the beginning of the perl script) but what I want to do is=20 =2D have one main script (called run.pl) with the Log4perl initialization (= only=20 here) =2D execute other scripts in a loop (1.pl ... 10.pl) from run.pl (in these scripts I dont have a new Log4perl initialization ,(so no 'filen= ame=20 =3D sub { "$0.log" }' ) =2D I just want to start and write to a new logfile when I start a new scri= pt in=20 the loop =2D the scripts are using a old subroutine inside , Prints::print_log($text) and I changed Prints::print_log($text) to =20 package Prints; sub print_log { $logger->info(shift); } the scripts I cant change (no log4perl statements inside them) so the change of the name for the logfile has to be done in the main script= =20 run.pl so I added for every new script a new FileApp with the right logfile name,= =20 executed the script and removed the appender. This works, but I dont have t= he=20 possibility to configure the FileApp with the Log4perl configuration file because every= =20 appender has a differnt name. I have to do it inside the code of run.pl which is not so nice. But I still wonder how to do this in the 'right and easy' way. or maybe=20 perl.appender.FileApp.filename =3D sub { "$0.log" } was already the solution (I havent tried)?? Thanks for your help J=FCrgen On Friday 09 March 2007 23:06, Mike Schilli wrote: > On Fri, 9 Mar 2007, [iso-8859-1] J=FCrgen Sch=F6neberg wrote: > > the problem: > > > > I want to execute a number of different perl scripts (named > > 1.pl..10.pl in the code below) . > > Just use a subroutine in your Log4perl configuration: > > log4perl.appender.FileApp.filename =3D sub { "$0.log" } > > This will even work if you stuff your l4p configuration into a config > file. > > -- Mike > > Mike Schilli > m...@pe... > > > every executed file should be logged to a corresponding logfile (1.log = =2E. > > 10.log) > > > > I want to have the same layout for the log in the files as on the screen > > and want to configure all with a configuration file for log4perl > > (in the code below its done in a string instead) > > > > > > what is the recommended way to change the name of the logfiles in > > runtime? > > > > I experimented a little with > > add_appender and remove_appender under runtime > > > > what's with file_switch($new_file_log); > > how can I use this? > > > > thanks for some explanations or even better some code examples! > > thank you for help > > > > Juergen > > > > > > > > > > here the frame code: > > > > #!/usr/bin/perl > > > > use warnings; > > use strict; > > > > use Log::Log4perl qw(get_logger); > > > > # Define configuration > > my $conf =3D q( > > log4perl.logger =3D ERROR, FileApp, ScreenApp > > log4perl.appender.FileApp =3D Log::Log4perl::Appender::File > > log4perl.appender.FileApp.filename =3D test.log > > log4perl.appender.FileApp.layout =3D PatternLayout > > log4perl.appender.FileApp.layout.ConversionPattern =3D %d> %m%n > > > > log4perl.appender.ScreenApp =3D > > Log::Log4perl::Appender::Screen log4perl.appender.ScreenApp.layout =3D > > PatternLayout > > log4perl.appender.ScreenApp.layout.ConversionPattern =3D %d> %m%n > > > > > > ); > > > > # Initialize logging behaviour > > Log::Log4perl->init( \$conf ); > > > > # Obtain a logger instance > > my $logger =3D get_logger("test"); > > > > > > foreach my $new_file (1..10) { > > > > $new_file_log .=3D '.log'; > > > > # > > # do '$new_file'.'.pl'; > > # > > > > } > > > > > > > > -----------------------------------------------------------------------= =2D- > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to share > > your opinions on IT & business topics through brief surveys-and earn ca= sh > > http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID= =3DDEVDEV > > _______________________________________________ > > log4perl-devel mailing list > > log...@li... > > https://lists.sourceforge.net/lists/listinfo/log4perl-devel |