From: Craig <cr...@po...> - 2008-05-23 02:23:23
|
Hi. I have an app where I want to log the following: stdout: ERROR stderr: ERROR file: INFO Also, I need to be able to change the level for stdout during run-time. I have a simple test script with the following config: $conf = { 'log4perl.logger' => "ERROR, Screen, OutError, File", 'log4perl.filter.Info' => 'Log::Log4perl::Filter::LevelRange', 'log4perl.filter.Info.LevelMin' => 'INFO', 'log4perl.filter.Info.LevelMax' => 'FATAL', 'log4perl.filter.Info.AcceptOnMatch' => 'true', 'log4perl.filter.Warn' => 'Log::Log4perl::Filter::LevelRange', 'log4perl.filter.Warn.LevelMin' => 'WARN', 'log4perl.filter.Warn.LevelMax' => 'FATAL', 'log4perl.filter.Warn.AcceptOnMatch' => 'true', "log4perl.appender.Screen" => "Log::Log4perl::Appender::Screen", "log4perl.appender.Screen.stderr" => "0", "log4perl.appender.Screen.layout" => "Log::Log4perl::Layout::PatternLayout", "log4perl.appender.Screen.layout.ConversionPattern" => 'ok: %p>%M-%L: %m%n', "log4perl.appender.OutError" => "Log::Log4perl::Appender::Screen", "log4perl.appender.OutError.Filter" => 'Warn', "log4perl.appender.OutError.stderr" => "1", "log4perl.appender.OutError.layout" => "Log::Log4perl::Layout::PatternLayout", "log4perl.appender.OutError.layout.ConversionPattern" => 'ok: %p>%M-%L: %m%n', "log4perl.appender.File" => "Log::Log4perl::Appender::File", "log4perl.appender.File.Filter" => 'Info', "log4perl.appender.File.mode" => 'append', "log4perl.appender.File.filename" => "app-multi.log", "log4perl.appender.File.layout" => "Log::Log4perl::Layout::PatternLayout", "log4perl.appender.File.layout.ConversionPattern" => '%p>%M-%L: %m%n' }; Log::Log4perl::init($conf); $logger = get_logger($name); ... ######################### Problem is that I need to *always* send info (and "up") messages to the file and error (and "up") to stderr regardless of what the root logger level is set to. But, I also need to be able to change the stdout level on the fly. I don't want to set the default root level to anything less than ERROR, which means that only error and up will then be sent to the file. (Basically, I have a "verbose" switch on the app where I turn down the level for stdout. But, the default should be pretty non-chatty.) Does this all make sense? (Not sure if I explained it very well.) Any ideas would be appreciated! Thanx Craig |
From: Mike S. <m...@pe...> - 2008-05-23 06:10:43
|
On Thu, 22 May 2008, Craig wrote: > Problem is that I need to *always* send info (and "up") messages to the > file and error (and "up") to stderr regardless of what the root logger > level is set to. But, I also need to be able to change the stdout level > on the fly. I don't want to set the default root level to anything less > than ERROR, which means that only error and up will then be sent to the > file. Not sure I understand why it's a requirement that the root logger's level is not set to anything less than ERROR. If you want INFO messages to go through, you can't close the first gate, keep the messages out and hope that the second gate (the filter) magically resurrects them -- that doesn't make sense. Why aren't you simply setting the logger to the lowest level you're interested in (INFO if I understood correctly) and handle the messages you don't want in the appenders with a threshold setting? http://log4perl.sourceforge.net/d/Log/Log4perl/FAQ.html#245ae -- Mike Mike Schilli m...@pe... > > I have an app where I want to log the following: > stdout: ERROR > stderr: ERROR > file: INFO > Also, I need to be able to change the level for stdout during run-time. > > I have a simple test script with the following config: > > $conf = { > 'log4perl.logger' => "ERROR, Screen, OutError, File", > > 'log4perl.filter.Info' => 'Log::Log4perl::Filter::LevelRange', > 'log4perl.filter.Info.LevelMin' => 'INFO', > 'log4perl.filter.Info.LevelMax' => 'FATAL', > 'log4perl.filter.Info.AcceptOnMatch' => 'true', > > 'log4perl.filter.Warn' => 'Log::Log4perl::Filter::LevelRange', > 'log4perl.filter.Warn.LevelMin' => 'WARN', > 'log4perl.filter.Warn.LevelMax' => 'FATAL', > 'log4perl.filter.Warn.AcceptOnMatch' => 'true', > > "log4perl.appender.Screen" => "Log::Log4perl::Appender::Screen", > "log4perl.appender.Screen.stderr" => "0", > "log4perl.appender.Screen.layout" => "Log::Log4perl::Layout::PatternLayout", > "log4perl.appender.Screen.layout.ConversionPattern" => 'ok: %p>%M-%L: %m%n', > > "log4perl.appender.OutError" => "Log::Log4perl::Appender::Screen", > "log4perl.appender.OutError.Filter" => 'Warn', > "log4perl.appender.OutError.stderr" => "1", > "log4perl.appender.OutError.layout" => > "Log::Log4perl::Layout::PatternLayout", > "log4perl.appender.OutError.layout.ConversionPattern" => 'ok: %p>%M-%L: > %m%n', > > "log4perl.appender.File" => "Log::Log4perl::Appender::File", > "log4perl.appender.File.Filter" => 'Info', > "log4perl.appender.File.mode" => 'append', > "log4perl.appender.File.filename" => "app-multi.log", > "log4perl.appender.File.layout" => "Log::Log4perl::Layout::PatternLayout", > "log4perl.appender.File.layout.ConversionPattern" => '%p>%M-%L: %m%n' > }; > Log::Log4perl::init($conf); > $logger = get_logger($name); > > ... > ######################### > > (Basically, I have a "verbose" switch on the app where I turn down the > level for stdout. But, the default should be pretty non-chatty.) > > Does this all make sense? (Not sure if I explained it very well.) > > Any ideas would be appreciated! > > Thanx > Craig > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > log4perl-devel mailing list > log...@li... > https://lists.sourceforge.net/lists/listinfo/log4perl-devel > |
From: Craig <cr...@po...> - 2008-05-27 20:32:23
|
Sorry it took so long to get back to you. (Was out for a couple of days.) Mike Schilli wrote: > On Thu, 22 May 2008, Craig wrote: > >> Problem is that I need to *always* send info (and "up") messages to the >> file and error (and "up") to stderr regardless of what the root logger >> level is set to. But, I also need to be able to change the stdout level >> on the fly. I don't want to set the default root level to anything less >> than ERROR, which means that only error and up will then be sent to the >> file. > > Not sure I understand why it's a requirement that the root logger's > level is not set to anything less than ERROR. Let me start by saying that none of this is a "hard requirement". Also, I realize that I am trying to "shoe-horn" one instance of log4perl to do everything I want. The script is small and a "one-off". So, devoting a lot of time to it is kind of a waste of time. While working on the script, I was also trying to play with log4perl. > If you want INFO messages to go through, you can't close the first gate, > keep the messages out and hope that the second gate (the filter) > magically resurrects them -- that doesn't make sense. Sorry, I didn't understand the internals of the library. I didn't think of it as a series of gates. Rather, I thought each logger category was independent of the others. Reading the docs more completely, it is obvious that isn't true. (Inheritance wouldn't work if that were true.) > Why aren't you simply setting the logger to the lowest level you're > interested in (INFO if I understood correctly) and handle the messages > you don't want in the appenders with a threshold setting? There are 3 distinct logging parts: 1. all warnings to stderr 2. all warnings to the user (stdout) 3. ongoing logging of what the app has done I would like a file that contains data on what the app did, what it touched, how long it took ,etc. (FYI, this is #3.) But, the user shouldn't be shown a bunch of data that he a) doesn't care about and b) doesn't understand. It would probably confuse him. :) But, if something goes wrong (warn or "worse"), I want the user to see that. But, just in case he closes the window before I can look at it, I want the same messages saved into another file (via stderr). This is all easy. The twist is that I would like to be able to pass in a "verbosity level" and with that change the log level for just stdout. That makes it much easier for me to debug problems if/when they arise. While thinking about this over the weekend, I figured this may be possible by setting a filter function on stdout. That function would look at the verbosity level. Then stderr and the app log would have their own filters set to WARN and INFO. Then the root logger would be set to TRACE. Seems like a lot of overhead, but it is ONE way to get a fair amount of configuration pretty simply. Craig |
From: Mike S. <m...@pe...> - 2008-06-08 19:14:38
|
On Tue, 27 May 2008, Craig wrote: > Sorry, I didn't understand the internals of the library. I didn't > think of it as a series of gates. Rather, I thought each logger > category was independent of the others. Reading the docs more > completely, it is obvious that isn't true. (Inheritance wouldn't work > if that were true.) Right, loggers in different parts of the hierarchy are independent of each other, while loggers that share the same lineage inherit from each other, you get this 'message bubbling up' effect. Filters, on the other hand, are separate from loggers and are associated with appenders to give them the opportunity to make a last deciding call on whether to log a message approved by a logger or not. > > Why aren't you simply setting the logger to the lowest level you're > > interested in (INFO if I understood correctly) and handle the > > messages you don't want in the appenders with a threshold setting? > > There are 3 distinct logging parts: > 1. all warnings to stderr > 2. all warnings to the user (stdout) > 3. ongoing logging of what the app has done > > I would like a file that contains data on what the app did, what it > touched, how long it took ,etc. (FYI, this is #3.) But, the user > shouldn't be shown a bunch of data that he a) doesn't care about and b) > doesn't understand. It would probably confuse him. :) No problem at all, that's exactly what you can do with filters. > This is all easy. The twist is that I would like to be able to pass in > a "verbosity level" and with that change the log level for just > stdout. That makes it much easier for me to debug problems if/when > they arise. I usually do that by switching to a more chatty log4perl configuration when I see that the user specified the '--verbose' or '-v' option. You can either have a separate log4perl config file or use a string to initialize log4perl. > While thinking about this over the weekend, I figured this may be > possible by setting a filter function on stdout. That function would > look at the verbosity level. > > Then stderr and the app log would have their own filters set to WARN and > INFO. Then the root logger would be set to TRACE. Seems like a lot of > overhead, but it is ONE way to get a fair amount of configuration pretty > simply. That's the way to go! :) -- Mike Mike Schilli m...@pe... |