Re: LevelRangeFilter not working
Hi Matt, I think you might have 2 filters confused. LevelRangeFilter needs a range of Levels to accept/deny. In your case you have said that the Maximum is Error, but have no Minimum set and therefore only logs with levels greater than error will get denied. You are probably wanting the LevelMatchFilter which takes a single level to match, and only accepts those, denies all others. Otherwise you could set the LevelMin of the LevelRangeFilter to ERROR and that should work too, I think. cheers, Paul Smith On Sat, 2003-09-06 at 07:55, Matt Raible wrote: > I two appenders - a console and a file. I want all messages to go to > the console and only <= error to go to the file. > > In my file appender, I have a filter to only get the error messages: > > > > > > Then in I have: > > > > > > > > From the documentation I've read (i.e. http://tinyurl.com/meef), this > *should* work. However, all messages get logged to both the console > appender and the file appender. > > Help is appreciated. > > Matt > > My full log4j.xml file: > > > > > http://jakarta.apache.org/log4j/";> > > > > > > > >class="org.apache.log4j.RollingFileAppender"> > value="${catalina.home}[EMAIL PROTECTED]@/error.log"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: LevelRangeFilter not working
I believe I have it configured correctly. I want to log messages that are FATAL or ERROR - nothing above error. Matt -Original Message- From: Paul Smith [mailto:[EMAIL PROTECTED] Sent: Sunday, September 07, 2003 4:05 PM To: Log4J Users List Subject: Re: LevelRangeFilter not working Hi Matt, I think you might have 2 filters confused. LevelRangeFilter needs a range of Levels to accept/deny. In your case you have said that the Maximum is Error, but have no Minimum set and therefore only logs with levels greater than error will get denied. You are probably wanting the LevelMatchFilter which takes a single level to match, and only accepts those, denies all others. Otherwise you could set the LevelMin of the LevelRangeFilter to ERROR and that should work too, I think. cheers, Paul Smith On Sat, 2003-09-06 at 07:55, Matt Raible wrote: > I two appenders - a console and a file. I want all messages to go to > the console and only <= error to go to the file. > > In my file appender, I have a filter to only get the error messages: > > > > > > Then in I have: > > > > > > > > From the documentation I've read (i.e. http://tinyurl.com/meef), this > *should* work. However, all messages get logged to both the console > appender and the file appender. > > Help is appreciated. > > Matt > > My full log4j.xml file: > > > > > http://jakarta.apache.org/log4j/";> > > > > > > > >class="org.apache.log4j.RollingFileAppender"> > value="${catalina.home}[EMAIL PROTECTED]@/error.log"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: LevelRangeFilter not working
Sorry, I got confused when you said "<=Error" in your original post, was that a typo, did you mean >=Error? Ok, to confirm, you only want ERROR and FATAL to go to your file appender, and allow all errors to go to the console? cheers, Paul On Mon, 2003-09-08 at 08:12, Matt Raible wrote: > I believe I have it configured correctly. I want to log messages that > are FATAL or ERROR - nothing above error. > > Matt > > -Original Message- > From: Paul Smith [mailto:[EMAIL PROTECTED] > Sent: Sunday, September 07, 2003 4:05 PM > To: Log4J Users List > Subject: Re: LevelRangeFilter not working > > > Hi Matt, > > I think you might have 2 filters confused. LevelRangeFilter needs a > range of Levels to accept/deny. In your case you have said that the > Maximum is Error, but have no Minimum set and therefore only logs with > levels greater than error will get denied. > > You are probably wanting the LevelMatchFilter which takes a single level > to match, and only accepts those, denies all others. > > Otherwise you could set the LevelMin of the LevelRangeFilter to ERROR > and that should work too, I think. > > cheers, > > Paul Smith > > On Sat, 2003-09-06 at 07:55, Matt Raible wrote: > > I two appenders - a console and a file. I want all messages to go to > > the console and only <= error to go to the file. > > > > In my file appender, I have a filter to only get the error messages: > > > > > > > > > > > > Then in I have: > > > > > > > > > > > > > > > > From the documentation I've read (i.e. http://tinyurl.com/meef), this > > *should* work. However, all messages get logged to both the console > > appender and the file appender. > > > > Help is appreciated. > > > > Matt > > > > My full log4j.xml file: > > > > > > > > > > http://jakarta.apache.org/log4j/";> > > > > > > > > > > > > > > > >> class="org.apache.log4j.RollingFileAppender"> > > > value="${catalina.home}[EMAIL PROTECTED]@/error.log"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: LevelRangeFilter not working
Yep - I only want ERROR and FATAL to go to my file appender and all messages (fatal -> debug) to go to the console. -Original Message- From: Paul Smith [mailto:[EMAIL PROTECTED] Sent: Sunday, September 07, 2003 4:18 PM To: Log4J Users List Subject: RE: LevelRangeFilter not working Sorry, I got confused when you said "<=Error" in your original post, was that a typo, did you mean >=Error? Ok, to confirm, you only want ERROR and FATAL to go to your file appender, and allow all errors to go to the console? cheers, Paul On Mon, 2003-09-08 at 08:12, Matt Raible wrote: > I believe I have it configured correctly. I want to log messages that > are FATAL or ERROR - nothing above error. > > Matt > > -Original Message- > From: Paul Smith [mailto:[EMAIL PROTECTED] > Sent: Sunday, September 07, 2003 4:05 PM > To: Log4J Users List > Subject: Re: LevelRangeFilter not working > > > Hi Matt, > > I think you might have 2 filters confused. LevelRangeFilter needs a > range of Levels to accept/deny. In your case you have said that the > Maximum is Error, but have no Minimum set and therefore only logs with > levels greater than error will get denied. > > You are probably wanting the LevelMatchFilter which takes a single > level to match, and only accepts those, denies all others. > > Otherwise you could set the LevelMin of the LevelRangeFilter to ERROR > and that should work too, I think. > > cheers, > > Paul Smith > > On Sat, 2003-09-06 at 07:55, Matt Raible wrote: > > I two appenders - a console and a file. I want all messages to go > > to > > the console and only <= error to go to the file. > > > > In my file appender, I have a filter to only get the error messages: > > > > > > > > > > > > Then in I have: > > > > > > > > > > > > > > > > From the documentation I've read (i.e. http://tinyurl.com/meef), > > this > > *should* work. However, all messages get logged to both the console > > appender and the file appender. > > > > Help is appreciated. > > > > Matt > > > > My full log4j.xml file: > > > > > > > > > > http://jakarta.apache.org/log4j/";> > > > > > > > > > > > > > > > >> class="org.apache.log4j.RollingFileAppender"> > > > value="${catalina.home}[EMAIL PROTECTED]@/error.log"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: LevelRangeFilter not working
Ok, if that is the case, then you definately want a LevelRangeFilter, and you want to set the MinLevel to ERROR, and the MaxLevel to FATAL (or don't have a Max). Here is the source code the relevant method inside LevelRangeFilter, you can see how it works: public int decide(LoggingEvent event) { if(this.levelMin != null) { if (event.getLevel().isGreaterOrEqual(levelMin) == false) { // level of event is less than minimum return Filter.DENY; } } if(this.levelMax != null) { if (event.getLevel().toInt() > levelMax.toInt()) { // level of event is greater than maximum // Alas, there is no Level.isGreater method. and using // a combo of isGreaterOrEqual && !Equal seems worse than // checking the int values of the level objects.. return Filter.DENY; } } if (acceptOnMatch) { // this filter set up to bypass later filters and always return // accept if level in range return Filter.ACCEPT; } else { // event is ok for this filter; allow later filters to have a look.. return Filter.NEUTRAL; } } Hope this helps, Paul On Mon, 2003-09-08 at 08:45, Matt Raible wrote: > Yep - I only want ERROR and FATAL to go to my file appender and all > messages (fatal -> debug) to go to the console. > > -Original Message- > From: Paul Smith [mailto:[EMAIL PROTECTED] > Sent: Sunday, September 07, 2003 4:18 PM > To: Log4J Users List > Subject: RE: LevelRangeFilter not working > > > Sorry, I got confused when you said "<=Error" in your original post, was > that a typo, did you mean >=Error? > > Ok, to confirm, you only want ERROR and FATAL to go to your file > appender, and allow all errors to go to the console? > > cheers, > > Paul > > On Mon, 2003-09-08 at 08:12, Matt Raible wrote: > > I believe I have it configured correctly. I want to log messages that > > > are FATAL or ERROR - nothing above error. > > > > Matt > > > > -Original Message- > > From: Paul Smith [mailto:[EMAIL PROTECTED] > > Sent: Sunday, September 07, 2003 4:05 PM > > To: Log4J Users List > > Subject: Re: LevelRangeFilter not working > > > > > > Hi Matt, > > > > I think you might have 2 filters confused. LevelRangeFilter needs a > > range of Levels to accept/deny. In your case you have said that the > > Maximum is Error, but have no Minimum set and therefore only logs with > > > levels greater than error will get denied. > > > > You are probably wanting the LevelMatchFilter which takes a single > > level to match, and only accepts those, denies all others. > > > > Otherwise you could set the LevelMin of the LevelRangeFilter to ERROR > > and that should work too, I think. > > > > cheers, > > > > Paul Smith > > > > On Sat, 2003-09-06 at 07:55, Matt Raible wrote: > > > I two appenders - a console and a file. I want all messages to go > > > to > > > the console and only <= error to go to the file. > > > > > > In my file appender, I have a filter to only get the error messages: > > > > > > > > > > > > > > > > > > Then in I have: > > > > > > > > > > > > > > > > > > > > > > > > From the documentation I've read (i.e. http://tinyurl.com/meef), > > > this > > > *should* work. However, all messages get logged to both the console > > > > appender and the file appender. > > > > > > Help is appreciated. > > > > > > Matt > > > > > > My full log4j.xml file: > > > > > > > > > > > > > > > http://jakarta.apache.org/log4j/";> > > > > > > > > > > > > > > > > > > > > > > > >> > class="org.apache.log4j.RollingFileAppender"> > > > > > value="${catalina.home}[EMAIL PROTECTED]@/error.log"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > - > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED]
RE: LevelRangeFilter not working
Thanks - looks like I had my mins and maxs mixed up - I thought Fatal was the min and Debug was the max, but now I can see it's the other way around. Your help is appreciated. Matt -Original Message- From: Paul Smith [mailto:[EMAIL PROTECTED] Sent: Sunday, September 07, 2003 4:55 PM To: Log4J Users List Subject: RE: LevelRangeFilter not working Ok, if that is the case, then you definately want a LevelRangeFilter, and you want to set the MinLevel to ERROR, and the MaxLevel to FATAL (or don't have a Max). Here is the source code the relevant method inside LevelRangeFilter, you can see how it works: public int decide(LoggingEvent event) { if(this.levelMin != null) { if (event.getLevel().isGreaterOrEqual(levelMin) == false) { // level of event is less than minimum return Filter.DENY; } } if(this.levelMax != null) { if (event.getLevel().toInt() > levelMax.toInt()) { // level of event is greater than maximum // Alas, there is no Level.isGreater method. and using // a combo of isGreaterOrEqual && !Equal seems worse than // checking the int values of the level objects.. return Filter.DENY; } } if (acceptOnMatch) { // this filter set up to bypass later filters and always return // accept if level in range return Filter.ACCEPT; } else { // event is ok for this filter; allow later filters to have a look.. return Filter.NEUTRAL; } } Hope this helps, Paul On Mon, 2003-09-08 at 08:45, Matt Raible wrote: > Yep - I only want ERROR and FATAL to go to my file appender and all > messages (fatal -> debug) to go to the console. > > -Original Message- > From: Paul Smith [mailto:[EMAIL PROTECTED] > Sent: Sunday, September 07, 2003 4:18 PM > To: Log4J Users List > Subject: RE: LevelRangeFilter not working > > > Sorry, I got confused when you said "<=Error" in your original post, > was that a typo, did you mean >=Error? > > Ok, to confirm, you only want ERROR and FATAL to go to your file > appender, and allow all errors to go to the console? > > cheers, > > Paul > > On Mon, 2003-09-08 at 08:12, Matt Raible wrote: > > I believe I have it configured correctly. I want to log messages > > that > > > are FATAL or ERROR - nothing above error. > > > > Matt > > > > -Original Message- > > From: Paul Smith [mailto:[EMAIL PROTECTED] > > Sent: Sunday, September 07, 2003 4:05 PM > > To: Log4J Users List > > Subject: Re: LevelRangeFilter not working > > > > > > Hi Matt, > > > > I think you might have 2 filters confused. LevelRangeFilter needs a > > range of Levels to accept/deny. In your case you have said that the > > Maximum is Error, but have no Minimum set and therefore only logs with > > > levels greater than error will get denied. > > > > You are probably wanting the LevelMatchFilter which takes a single > > level to match, and only accepts those, denies all others. > > > > Otherwise you could set the LevelMin of the LevelRangeFilter to > > ERROR > > and that should work too, I think. > > > > cheers, > > > > Paul Smith > > > > On Sat, 2003-09-06 at 07:55, Matt Raible wrote: > > > I two appenders - a console and a file. I want all messages to go > > > to > > > the console and only <= error to go to the file. > > > > > > In my file appender, I have a filter to only get the error > > > messages: > > > > > > > > > > > > > > > > > > Then in I have: > > > > > > > > > > > > > > > > > > > > > > > > From the documentation I've read (i.e. http://tinyurl.com/meef), > > > this > > > *should* work. However, all messages get logged to both the console > > > > appender and the file appender. > > > > > > Help is appreciated. > > > > > > Matt > > > > > > My full log4j.xml file: > > > > > > > > > > > > > > > > > xmlns:log4j="http://jakarta.apache.org/log4j/";> > > > > > > > > > > > > > > > > > > > > > > > >> > class="org.apache.log4j.RollingFileAppender"> > > > > > value="${catalina.home}[EMAIL PROTECTED]@/error.log"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > -- > > > - > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > -
Elementary question
Hi, I am trying to configure log4j for an app. Currently, I have deployed it on Tomcat. My code snippet is - .. String configFileName = "com.common.logger.xml"; URL url = null; Context ctx=null; ctx = new InitialContext(); url = ctx.getClass().getResource(configFileName); . I put the xml file under a directory structure under classes in my web-app. The issue is that the URL is null. I also tried other options like making the string \com\common\logger.xml and com\common\logger.xml Another approach I tried was to get Thread.currentThread.getClassLoader and read the URL from there, I get a vague null pointer exception and zip exception. I am sorry if this is a very elementary question, but I could not find any solutions in the lists also. Krishna. - Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software
Re: Elementary question
Try this... String configFileName = "/com/common/logger.xml"; Always use forward slashes when dealing with class loader paths. These are Java packages, not system directories (even though they look similar). One other thing. Where is the class you are using to load the logger.xml file? Is it in the same package as logger.xml (actually, I just noticed it is the InitialContext class, so the answer is no, it isn't in the same package, but anyway...)? If so, then just do.. String configFileName = "logger.xml"; When using the getResource() method from the Class class, resources are relative to the class. Notice in the first example that I overrode this the relative path by including a preceding forward slash which makes it look for the resource starting from the root package. You can also use the ClassLoader.getResource() method and remove the preceding forward slash to do the same thing. Jake At 07:23 PM 9/7/2003 -0700, you wrote: Hi, I am trying to configure log4j for an app. Currently, I have deployed it on Tomcat. My code snippet is - .. String configFileName = "com.common.logger.xml"; URL url = null; Context ctx=null; ctx = new InitialContext(); url = ctx.getClass().getResource(configFileName); . I put the xml file under a directory structure under classes in my web-app. The issue is that the URL is null. I also tried other options like making the string \com\common\logger.xml and com\common\logger.xml Another approach I tried was to get Thread.currentThread.getClassLoader and read the URL from there, I get a vague null pointer exception and zip exception. I am sorry if this is a very elementary question, but I could not find any solutions in the lists also. Krishna. - Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Elementary question
Hi Jake, thankou for the mail. I tried with forward slashes "\", but the context does not seem to like it, I keep gettin the URL as null. Jacob Kjome <[EMAIL PROTECTED]> wrote: Try this... String configFileName = "/com/common/logger.xml"; Always use forward slashes when dealing with class loader paths. These are Java packages, not system directories (even though they look similar). One other thing. Where is the class you are using to load the logger.xml file? Is it in the same package as logger.xml (actually, I just noticed it is the InitialContext class, so the answer is no, it isn't in the same package, but anyway...)? If so, then just do.. String configFileName = "logger.xml"; When using the getResource() method from the Class class, resources are relative to the class. Notice in the first example that I overrode this the relative path by including a preceding forward slash which makes it look for the resource starting from the root package. You can also use the ClassLoader.getResource() method and remove the preceding forward slash to do the same thing. Jake At 07:23 PM 9/7/2003 -0700, you wrote: >Hi, > >I am trying to configure log4j for an app. Currently, I have deployed >it on Tomcat. My code snippet is - > >.. >String configFileName = "com.common.logger.xml"; >URL url = null; >Context ctx=null; >ctx = new InitialContext(); >url = ctx.getClass().getResource(configFileName); >. > >I put the xml file under a directory structure under classes in my >web-app. The issue is that the URL is null. > >I also tried other options like making the string >\com\common\logger.xml and com\common\logger.xml > >Another approach I tried was to get Thread.currentThread.getClassLoader >and read the URL from there, I get a vague null pointer exception and >zip exception. > >I am sorry if this is a very elementary question, but I could not find >any solutions in the lists also. > >Krishna. > > > >- >Do you Yahoo!? >Yahoo! SiteBuilder - Free, easy-to-use web site design software - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software
Re: Elementary question
InitialContext is probably loaded from a parent class loader and can't see the resource in your child class loader. Why are you using InitialContext in this situation anyway? Just use the class you are performing this from. Let's call it MyClass in a static context... MyClass.class.getResource(configFileName); in an object context... this.getClass().getResource(configFileName); There is no reason this shouldn't work. Jake At 08:06 PM 9/7/2003 -0700, you wrote: Hi Jake, thankou for the mail. I tried with forward slashes "\", but the context does not seem to like it, I keep gettin the URL as null. Jacob Kjome <[EMAIL PROTECTED]> wrote: Try this... String configFileName = "/com/common/logger.xml"; Always use forward slashes when dealing with class loader paths. These are Java packages, not system directories (even though they look similar). One other thing. Where is the class you are using to load the logger.xml file? Is it in the same package as logger.xml (actually, I just noticed it is the InitialContext class, so the answer is no, it isn't in the same package, but anyway...)? If so, then just do.. String configFileName = "logger.xml"; When using the getResource() method from the Class class, resources are relative to the class. Notice in the first example that I overrode this the relative path by including a preceding forward slash which makes it look for the resource starting from the root package. You can also use the ClassLoader.getResource() method and remove the preceding forward slash to do the same thing. Jake At 07:23 PM 9/7/2003 -0700, you wrote: >Hi, > >I am trying to configure log4j for an app. Currently, I have deployed >it on Tomcat. My code snippet is - > >.. >String configFileName = "com.common.logger.xml"; >URL url = null; >Context ctx=null; >ctx = new InitialContext(); >url = ctx.getClass().getResource(configFileName); >. > >I put the xml file under a directory structure under classes in my >web-app. The issue is that the URL is null. > >I also tried other options like making the string >\com\common\logger.xml and com\common\logger.xml > >Another approach I tried was to get Thread.currentThread.getClassLoader >and read the URL from there, I get a vague null pointer exception and >zip exception. > >I am sorry if this is a very elementary question, but I could not find >any solutions in the lists also. > >Krishna. > > > >- >Do you Yahoo!? >Yahoo! SiteBuilder - Free, easy-to-use web site design software - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]