You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Nicholas Duane <ni...@msn.com> on 2015/08/26 20:19:11 UTC

custom levels via configuration



On to my next problem.  I'm trying to define a custom level in configuration.  Not sure if it's working or not.  However, when I attempt to get the level for that custom level I get back null, which I wasn't expecting.  Here is the log4j2.xml config file:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" verbose="true">
  <CustomLevels>
    <CustomLevel name="INFOM1" intLevel="399"/>
    <CustomLevel name="INFOP1" intLevel="401"/>
  </CustomLevels>
  <Appenders>
    <File name="info" fileName="info.log">
      <PatternLayout>
    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
      </PatternLayout>
      <Filters>
    <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
    <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
      </Filters>
    </File>
  </Appenders>
  <Loggers>
    <Logger name="HelloWorld" level="ALL">
      <AppenderRef ref="info"/>
    </Logger>
    <Root>
    </Root>
  </Loggers>
</Configuration>

Here is my code:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Level;

public class HelloWorld
{ 
    static Logger log = LogManager.getLogger(HelloWorld.class.getName());

    public static void main(String[] args)
    { 
      System.out.println("Hello, World");
      log.info("hello this is an INFO  message");
      log.warn("hello this is a WARN message");
      log.debug("hello this is a DEBUG message");
      Level level = Level.getLevel("INFOM1");
      if (level == null)
    System.out.println("Didn't find level INFOM1");
      else
        log.log(level, "hello this is an INFOM1 message");
      level = Level.getLevel("INFOP1");
      if (level == null)
    System.out.println("Didn't find level INFOP1");
      else
        log.log(level, "hello this is an INFOP1 message");
    }
}

Any ideas?  I obviously don't want to use Level.forName() as that will create the level if it doesn't exist and I want to ensure I'm pulling the value from the configuration.

Thanks,
Nick

 		 	   		  

Re: custom levels via configuration

Posted by Ralph Goers <ra...@dslextreme.com>.
OFF has a value of 0. What would it mean to have a value less than that?

Ralph

> On Aug 29, 2015, at 7:22 PM, Nicholas Duane <ni...@msn.com> wrote:
> 
> I got log4j 2.3 installed and verified that custom levels are working for me now.  However, I did noticed you can't set the intValue to a negative number.  Is that by design?
> 
> Thanks,
> Nick
> 
>> From: nickdu@msn.com
>> To: log4j-user@logging.apache.org
>> Subject: RE: custom levels via configuration
>> Date: Wed, 26 Aug 2015 20:34:13 -0400
>> 
>> That would certainly be a possible explanation.  I'm working on figuring out how to upgrade to log4j 2.3.  Hopefully that will solve my custom levels issue.
>> 
>> Thanks,
>> Nick
>> 
>>> Subject: Re: custom levels via configuration
>>> From: ralph.goers@dslextreme.com
>>> Date: Wed, 26 Aug 2015 17:05:02 -0700
>>> To: log4j-user@logging.apache.org
>>> 
>>> Custom log levels weren’t added to Log4j 2 until version 2.1, so if the version you are using is older than that it is no surprise that it isn’t working.
>>> 
>>> Ralph
>>> 
>>>> On Aug 26, 2015, at 2:34 PM, Nicholas Duane <ni...@msn.com> wrote:
>>>> 
>>>> While I work on figuring out how to get a newer version of log4j2 installed I'm wondering whether there is some additional investigation I can do with the version I have.  For instance, I was hoping with the level of logging I have enabled, that log4j would be indicating some issue it had with the custom level.  However, I don't see such an issue.  The only thing I see is an issue with the custom level, which I'm guessing is when I'm using it in the filter.  I've attached the warning in the log below.
>>>> 
>>>> Is there some additional logging I can turn on such that log4j will produce more info which might indicate why my custom levels aren't working?  Here is my current log4j2 configuration.
>>>> 
>>>> log4j2.xml:
>>>> 
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <Configuration status="trace" verbose="true">
>>>> <CustomLevels>
>>>>   <CustomLevel name="INFOM1" intLevel="399"/>
>>>>   <CustomLevel name="INFOP1" intLevel="401"/>
>>>> </CustomLevels>
>>>> <Appenders>
>>>>   <File name="info" fileName="info.log">
>>>>     <PatternLayout>
>>>>   <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
>>>>     </PatternLayout>
>>>>     <Filters>
>>>>   <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
>>>>   <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
>>>>     </Filters>
>>>>   </File>
>>>> </Appenders>
>>>> <Loggers>
>>>>   <Logger name="HelloWorld" level="ALL">
>>>>     <AppenderRef ref="info"/>
>>>>   </Logger>
>>>>   <Root>
>>>>   </Root>
>>>> </Loggers>
>>>> </Configuration>
>>>> 
>>>> snippet of console output:
>>>> 
>>>> 2015-08-26 14:26:21,070 WARN Error while converting string [INFOM1] to type [class org.apache.logging.log4j.Level]. Using default value [null]. java.lang.IllegalArgumentException: Unknown level constant [INFOM1].
>>>>   at org.apache.logging.log4j.Level.valueOf(Level.java:281)
>>>>   at org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:240)
>>>>   at org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:237)
>>>>   at org.apache.logging.log4j.core.config.plugins.util.TypeConverters.convert(TypeConverters.java:343)
>>>>   at org.apache.logging.log4j.core.config.plugins.visitors.AbstractPluginVisitor.convert(AbstractPluginVisitor.java:130)
>>>>   at org.apache.logging.log4j.core.config.plugins.visitors.PluginAttributeVisitor.visit(PluginAttributeVisitor.java:44)
>>>>   at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.generateParameters(PluginBuilder.java:233)
>>>>   at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:131)
>>>>   at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:748)
>>>>   at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:683)
>>>>   at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
>>>>   at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
>>>>   at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
>>>>   at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:349)
>>>>   at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:150)
>>>>   at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:358)
>>>>   at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:416)
>>>>   at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:146)
>>>>   at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:75)
>>>>   at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
>>>>   at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
>>>>   at HelloWorld.<clinit>(HelloWorld.java:7)
>>>> 
>>>> Thanks,
>>>> Nick
>>>> 
>>>>> Date: Wed, 26 Aug 2015 12:36:40 -0700
>>>>> Subject: Re: custom levels via configuration
>>>>> From: garydgregory@gmail.com
>>>>> To: log4j-user@logging.apache.org
>>>>> 
>>>>> We've never released a version "2.0-1.fc21" so it must be a Fedora build,
>>>>> presumably based on 2.0 or some fork of it.
>>>>> 
>>>>> You need to test with version 2.3 or a 2.4-SNAPSHOT. I'll leave you to
>>>>> Google how to install 2.3 on Fedora ;-)
>>>>> 
>>>>> Gary
>>>>> 
>>>>> On Wed, Aug 26, 2015 at 12:14 PM, Nicholas Duane <ni...@msn.com> wrote:
>>>>> 
>>>>>> First off let me admit that I'm a noob at both Linux and java, and log4j
>>>>>> for that matter.
>>>>>> 
>>>>>> I don't know how to package anything so my class that you see is a simple
>>>>>> java class which I compiled using javac.  I then run it using 'java
>>>>>> HelloWorld'.  I'm running fedora 21.  When I do a 'yum list log4j' it says
>>>>>> I have 2.0-1.fc21.
>>>>>> 
>>>>>> Thanks,
>>>>>> Nick
>>>>>> 
>>>>>>> Date: Wed, 26 Aug 2015 11:46:51 -0700
>>>>>>> Subject: Re: custom levels via configuration
>>>>>>> From: garydgregory@gmail.com
>>>>>>> To: log4j-user@logging.apache.org
>>>>>>> 
>>>>>>> This:
>>>>>>> 
>>>>>>> <Logger name="HelloWorld" level="ALL">
>>>>>>> 
>>>>>>> is only going to match:
>>>>>>> 
>>>>>>> static Logger log = LogManager.getLogger(HelloWorld.class.getName());
>>>>>>> 
>>>>>>> if the class in unpackaged, which it looks it is based on this paste but
>>>>>> I
>>>>>>> want to double check that you did not omit anything from the example.
>>>>>>> 
>>>>>>> Are you using the latest version (2.3)?.
>>>>>>> 
>>>>>>> I just added this test the other day to Git master:
>>>>>>> 
>>>>>>> org.apache.logging.log4j.core.CustomLevelsTest
>>>>>>> 
>>>>>>> And it shows that we can configure custom levels from a file and see them
>>>>>>> in code.
>>>>>>> 
>>>>>>> So I am puzzled here.
>>>>>>> 
>>>>>>> You could try the latest from Git master as well but I do not recall any
>>>>>>> fixes in this area.
>>>>>>> 
>>>>>>> I wonder if the Appenders are processed by the configuration _before_ the
>>>>>>> custom levels...
>>>>>>> 
>>>>>>> Gary
>>>>>>> 
>>>>>>> 
>>>>>>> On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com> wrote:
>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> On to my next problem.  I'm trying to define a custom level in
>>>>>>>> configuration.  Not sure if it's working or not.  However, when I
>>>>>> attempt
>>>>>>>> to get the level for that custom level I get back null, which I wasn't
>>>>>>>> expecting.  Here is the log4j2.xml config file:
>>>>>>>> 
>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>> <Configuration status="trace" verbose="true">
>>>>>>>> <CustomLevels>
>>>>>>>>   <CustomLevel name="INFOM1" intLevel="399"/>
>>>>>>>>   <CustomLevel name="INFOP1" intLevel="401"/>
>>>>>>>> </CustomLevels>
>>>>>>>> <Appenders>
>>>>>>>>   <File name="info" fileName="info.log">
>>>>>>>>     <PatternLayout>
>>>>>>>>   <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
>>>>>>>>     </PatternLayout>
>>>>>>>>     <Filters>
>>>>>>>>   <ThresholdFilter level="INFOM1" onMatch="DENY"
>>>>>> onMismatch="NEUTRAL"/>
>>>>>>>>   <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
>>>>>>>>     </Filters>
>>>>>>>>   </File>
>>>>>>>> </Appenders>
>>>>>>>> <Loggers>
>>>>>>>>   <Logger name="HelloWorld" level="ALL">
>>>>>>>>     <AppenderRef ref="info"/>
>>>>>>>>   </Logger>
>>>>>>>>   <Root>
>>>>>>>>   </Root>
>>>>>>>> </Loggers>
>>>>>>>> </Configuration>
>>>>>>>> 
>>>>>>>> Here is my code:
>>>>>>>> 
>>>>>>>> import org.apache.logging.log4j.LogManager;
>>>>>>>> import org.apache.logging.log4j.Logger;
>>>>>>>> import org.apache.logging.log4j.Level;
>>>>>>>> 
>>>>>>>> public class HelloWorld
>>>>>>>> {
>>>>>>>>   static Logger log =
>>>>>> LogManager.getLogger(HelloWorld.class.getName());
>>>>>>>> 
>>>>>>>>   public static void main(String[] args)
>>>>>>>>   {
>>>>>>>>     System.out.println("Hello, World");
>>>>>>>>     log.info("hello this is an INFO  message");
>>>>>>>>     log.warn("hello this is a WARN message");
>>>>>>>>     log.debug("hello this is a DEBUG message");
>>>>>>>>     Level level = Level.getLevel("INFOM1");
>>>>>>>>     if (level == null)
>>>>>>>>   System.out.println("Didn't find level INFOM1");
>>>>>>>>     else
>>>>>>>>       log.log(level, "hello this is an INFOM1 message");
>>>>>>>>     level = Level.getLevel("INFOP1");
>>>>>>>>     if (level == null)
>>>>>>>>   System.out.println("Didn't find level INFOP1");
>>>>>>>>     else
>>>>>>>>       log.log(level, "hello this is an INFOP1 message");
>>>>>>>>   }
>>>>>>>> }
>>>>>>>> 
>>>>>>>> Any ideas?  I obviously don't want to use Level.forName() as that will
>>>>>>>> create the level if it doesn't exist and I want to ensure I'm pulling
>>>>>> the
>>>>>>>> value from the configuration.
>>>>>>>> 
>>>>>>>> Thanks,
>>>>>>>> Nick
>>>>>>>> 
>>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> --
>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>> Home: http://garygregory.com/
>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>> 
>>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> -- 
>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>> Java Persistence with Hibernate, Second Edition
>>>>> <http://www.manning.com/bauer3/>
>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>> Blog: http://garygregory.wordpress.com
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>> 		 	   		  
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>> 
>> 		 	   		  
> 		 	   		  



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: custom levels via configuration

Posted by Nicholas Duane <ni...@msn.com>.
I got log4j 2.3 installed and verified that custom levels are working for me now.  However, I did noticed you can't set the intValue to a negative number.  Is that by design?

Thanks,
Nick

> From: nickdu@msn.com
> To: log4j-user@logging.apache.org
> Subject: RE: custom levels via configuration
> Date: Wed, 26 Aug 2015 20:34:13 -0400
> 
> That would certainly be a possible explanation.  I'm working on figuring out how to upgrade to log4j 2.3.  Hopefully that will solve my custom levels issue.
>  
> Thanks,
> Nick
>  
> > Subject: Re: custom levels via configuration
> > From: ralph.goers@dslextreme.com
> > Date: Wed, 26 Aug 2015 17:05:02 -0700
> > To: log4j-user@logging.apache.org
> > 
> > Custom log levels weren’t added to Log4j 2 until version 2.1, so if the version you are using is older than that it is no surprise that it isn’t working.
> > 
> > Ralph
> > 
> > > On Aug 26, 2015, at 2:34 PM, Nicholas Duane <ni...@msn.com> wrote:
> > > 
> > > While I work on figuring out how to get a newer version of log4j2 installed I'm wondering whether there is some additional investigation I can do with the version I have.  For instance, I was hoping with the level of logging I have enabled, that log4j would be indicating some issue it had with the custom level.  However, I don't see such an issue.  The only thing I see is an issue with the custom level, which I'm guessing is when I'm using it in the filter.  I've attached the warning in the log below.
> > > 
> > > Is there some additional logging I can turn on such that log4j will produce more info which might indicate why my custom levels aren't working?  Here is my current log4j2 configuration.
> > > 
> > > log4j2.xml:
> > > 
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <Configuration status="trace" verbose="true">
> > >  <CustomLevels>
> > >    <CustomLevel name="INFOM1" intLevel="399"/>
> > >    <CustomLevel name="INFOP1" intLevel="401"/>
> > >  </CustomLevels>
> > >  <Appenders>
> > >    <File name="info" fileName="info.log">
> > >      <PatternLayout>
> > >    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> > >      </PatternLayout>
> > >      <Filters>
> > >    <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
> > >    <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> > >      </Filters>
> > >    </File>
> > >  </Appenders>
> > >  <Loggers>
> > >    <Logger name="HelloWorld" level="ALL">
> > >      <AppenderRef ref="info"/>
> > >    </Logger>
> > >    <Root>
> > >    </Root>
> > >  </Loggers>
> > > </Configuration>
> > > 
> > > snippet of console output:
> > > 
> > > 2015-08-26 14:26:21,070 WARN Error while converting string [INFOM1] to type [class org.apache.logging.log4j.Level]. Using default value [null]. java.lang.IllegalArgumentException: Unknown level constant [INFOM1].
> > >    at org.apache.logging.log4j.Level.valueOf(Level.java:281)
> > >    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:240)
> > >    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:237)
> > >    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters.convert(TypeConverters.java:343)
> > >    at org.apache.logging.log4j.core.config.plugins.visitors.AbstractPluginVisitor.convert(AbstractPluginVisitor.java:130)
> > >    at org.apache.logging.log4j.core.config.plugins.visitors.PluginAttributeVisitor.visit(PluginAttributeVisitor.java:44)
> > >    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.generateParameters(PluginBuilder.java:233)
> > >    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:131)
> > >    at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:748)
> > >    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:683)
> > >    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
> > >    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
> > >    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
> > >    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:349)
> > >    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:150)
> > >    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:358)
> > >    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:416)
> > >    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:146)
> > >    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:75)
> > >    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
> > >    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
> > >    at HelloWorld.<clinit>(HelloWorld.java:7)
> > > 
> > > Thanks,
> > > Nick
> > > 
> > >> Date: Wed, 26 Aug 2015 12:36:40 -0700
> > >> Subject: Re: custom levels via configuration
> > >> From: garydgregory@gmail.com
> > >> To: log4j-user@logging.apache.org
> > >> 
> > >> We've never released a version "2.0-1.fc21" so it must be a Fedora build,
> > >> presumably based on 2.0 or some fork of it.
> > >> 
> > >> You need to test with version 2.3 or a 2.4-SNAPSHOT. I'll leave you to
> > >> Google how to install 2.3 on Fedora ;-)
> > >> 
> > >> Gary
> > >> 
> > >> On Wed, Aug 26, 2015 at 12:14 PM, Nicholas Duane <ni...@msn.com> wrote:
> > >> 
> > >>> First off let me admit that I'm a noob at both Linux and java, and log4j
> > >>> for that matter.
> > >>> 
> > >>> I don't know how to package anything so my class that you see is a simple
> > >>> java class which I compiled using javac.  I then run it using 'java
> > >>> HelloWorld'.  I'm running fedora 21.  When I do a 'yum list log4j' it says
> > >>> I have 2.0-1.fc21.
> > >>> 
> > >>> Thanks,
> > >>> Nick
> > >>> 
> > >>>> Date: Wed, 26 Aug 2015 11:46:51 -0700
> > >>>> Subject: Re: custom levels via configuration
> > >>>> From: garydgregory@gmail.com
> > >>>> To: log4j-user@logging.apache.org
> > >>>> 
> > >>>> This:
> > >>>> 
> > >>>> <Logger name="HelloWorld" level="ALL">
> > >>>> 
> > >>>> is only going to match:
> > >>>> 
> > >>>> static Logger log = LogManager.getLogger(HelloWorld.class.getName());
> > >>>> 
> > >>>> if the class in unpackaged, which it looks it is based on this paste but
> > >>> I
> > >>>> want to double check that you did not omit anything from the example.
> > >>>> 
> > >>>> Are you using the latest version (2.3)?.
> > >>>> 
> > >>>> I just added this test the other day to Git master:
> > >>>> 
> > >>>> org.apache.logging.log4j.core.CustomLevelsTest
> > >>>> 
> > >>>> And it shows that we can configure custom levels from a file and see them
> > >>>> in code.
> > >>>> 
> > >>>> So I am puzzled here.
> > >>>> 
> > >>>> You could try the latest from Git master as well but I do not recall any
> > >>>> fixes in this area.
> > >>>> 
> > >>>> I wonder if the Appenders are processed by the configuration _before_ the
> > >>>> custom levels...
> > >>>> 
> > >>>> Gary
> > >>>> 
> > >>>> 
> > >>>> On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com> wrote:
> > >>>> 
> > >>>>> 
> > >>>>> 
> > >>>>> 
> > >>>>> On to my next problem.  I'm trying to define a custom level in
> > >>>>> configuration.  Not sure if it's working or not.  However, when I
> > >>> attempt
> > >>>>> to get the level for that custom level I get back null, which I wasn't
> > >>>>> expecting.  Here is the log4j2.xml config file:
> > >>>>> 
> > >>>>> <?xml version="1.0" encoding="UTF-8"?>
> > >>>>> <Configuration status="trace" verbose="true">
> > >>>>>  <CustomLevels>
> > >>>>>    <CustomLevel name="INFOM1" intLevel="399"/>
> > >>>>>    <CustomLevel name="INFOP1" intLevel="401"/>
> > >>>>>  </CustomLevels>
> > >>>>>  <Appenders>
> > >>>>>    <File name="info" fileName="info.log">
> > >>>>>      <PatternLayout>
> > >>>>>    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> > >>>>>      </PatternLayout>
> > >>>>>      <Filters>
> > >>>>>    <ThresholdFilter level="INFOM1" onMatch="DENY"
> > >>> onMismatch="NEUTRAL"/>
> > >>>>>    <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> > >>>>>      </Filters>
> > >>>>>    </File>
> > >>>>>  </Appenders>
> > >>>>>  <Loggers>
> > >>>>>    <Logger name="HelloWorld" level="ALL">
> > >>>>>      <AppenderRef ref="info"/>
> > >>>>>    </Logger>
> > >>>>>    <Root>
> > >>>>>    </Root>
> > >>>>>  </Loggers>
> > >>>>> </Configuration>
> > >>>>> 
> > >>>>> Here is my code:
> > >>>>> 
> > >>>>> import org.apache.logging.log4j.LogManager;
> > >>>>> import org.apache.logging.log4j.Logger;
> > >>>>> import org.apache.logging.log4j.Level;
> > >>>>> 
> > >>>>> public class HelloWorld
> > >>>>> {
> > >>>>>    static Logger log =
> > >>> LogManager.getLogger(HelloWorld.class.getName());
> > >>>>> 
> > >>>>>    public static void main(String[] args)
> > >>>>>    {
> > >>>>>      System.out.println("Hello, World");
> > >>>>>      log.info("hello this is an INFO  message");
> > >>>>>      log.warn("hello this is a WARN message");
> > >>>>>      log.debug("hello this is a DEBUG message");
> > >>>>>      Level level = Level.getLevel("INFOM1");
> > >>>>>      if (level == null)
> > >>>>>    System.out.println("Didn't find level INFOM1");
> > >>>>>      else
> > >>>>>        log.log(level, "hello this is an INFOM1 message");
> > >>>>>      level = Level.getLevel("INFOP1");
> > >>>>>      if (level == null)
> > >>>>>    System.out.println("Didn't find level INFOP1");
> > >>>>>      else
> > >>>>>        log.log(level, "hello this is an INFOP1 message");
> > >>>>>    }
> > >>>>> }
> > >>>>> 
> > >>>>> Any ideas?  I obviously don't want to use Level.forName() as that will
> > >>>>> create the level if it doesn't exist and I want to ensure I'm pulling
> > >>> the
> > >>>>> value from the configuration.
> > >>>>> 
> > >>>>> Thanks,
> > >>>>> Nick
> > >>>>> 
> > >>>>> 
> > >>>> 
> > >>>> 
> > >>>> 
> > >>>> 
> > >>>> --
> > >>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > >>>> Java Persistence with Hibernate, Second Edition
> > >>>> <http://www.manning.com/bauer3/>
> > >>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > >>>> Spring Batch in Action <http://www.manning.com/templier/>
> > >>>> Blog: http://garygregory.wordpress.com
> > >>>> Home: http://garygregory.com/
> > >>>> Tweet! http://twitter.com/GaryGregory
> > >>> 
> > >>> 
> > >> 
> > >> 
> > >> 
> > >> -- 
> > >> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > >> Java Persistence with Hibernate, Second Edition
> > >> <http://www.manning.com/bauer3/>
> > >> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > >> Spring Batch in Action <http://www.manning.com/templier/>
> > >> Blog: http://garygregory.wordpress.com
> > >> Home: http://garygregory.com/
> > >> Tweet! http://twitter.com/GaryGregory
> > > 		 	   		  
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> > 
>  		 	   		  
 		 	   		  

RE: custom levels via configuration

Posted by Nicholas Duane <ni...@msn.com>.
That would certainly be a possible explanation.  I'm working on figuring out how to upgrade to log4j 2.3.  Hopefully that will solve my custom levels issue.
 
Thanks,
Nick
 
> Subject: Re: custom levels via configuration
> From: ralph.goers@dslextreme.com
> Date: Wed, 26 Aug 2015 17:05:02 -0700
> To: log4j-user@logging.apache.org
> 
> Custom log levels weren’t added to Log4j 2 until version 2.1, so if the version you are using is older than that it is no surprise that it isn’t working.
> 
> Ralph
> 
> > On Aug 26, 2015, at 2:34 PM, Nicholas Duane <ni...@msn.com> wrote:
> > 
> > While I work on figuring out how to get a newer version of log4j2 installed I'm wondering whether there is some additional investigation I can do with the version I have.  For instance, I was hoping with the level of logging I have enabled, that log4j would be indicating some issue it had with the custom level.  However, I don't see such an issue.  The only thing I see is an issue with the custom level, which I'm guessing is when I'm using it in the filter.  I've attached the warning in the log below.
> > 
> > Is there some additional logging I can turn on such that log4j will produce more info which might indicate why my custom levels aren't working?  Here is my current log4j2 configuration.
> > 
> > log4j2.xml:
> > 
> > <?xml version="1.0" encoding="UTF-8"?>
> > <Configuration status="trace" verbose="true">
> >  <CustomLevels>
> >    <CustomLevel name="INFOM1" intLevel="399"/>
> >    <CustomLevel name="INFOP1" intLevel="401"/>
> >  </CustomLevels>
> >  <Appenders>
> >    <File name="info" fileName="info.log">
> >      <PatternLayout>
> >    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> >      </PatternLayout>
> >      <Filters>
> >    <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
> >    <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> >      </Filters>
> >    </File>
> >  </Appenders>
> >  <Loggers>
> >    <Logger name="HelloWorld" level="ALL">
> >      <AppenderRef ref="info"/>
> >    </Logger>
> >    <Root>
> >    </Root>
> >  </Loggers>
> > </Configuration>
> > 
> > snippet of console output:
> > 
> > 2015-08-26 14:26:21,070 WARN Error while converting string [INFOM1] to type [class org.apache.logging.log4j.Level]. Using default value [null]. java.lang.IllegalArgumentException: Unknown level constant [INFOM1].
> >    at org.apache.logging.log4j.Level.valueOf(Level.java:281)
> >    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:240)
> >    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:237)
> >    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters.convert(TypeConverters.java:343)
> >    at org.apache.logging.log4j.core.config.plugins.visitors.AbstractPluginVisitor.convert(AbstractPluginVisitor.java:130)
> >    at org.apache.logging.log4j.core.config.plugins.visitors.PluginAttributeVisitor.visit(PluginAttributeVisitor.java:44)
> >    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.generateParameters(PluginBuilder.java:233)
> >    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:131)
> >    at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:748)
> >    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:683)
> >    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
> >    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
> >    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
> >    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:349)
> >    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:150)
> >    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:358)
> >    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:416)
> >    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:146)
> >    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:75)
> >    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
> >    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
> >    at HelloWorld.<clinit>(HelloWorld.java:7)
> > 
> > Thanks,
> > Nick
> > 
> >> Date: Wed, 26 Aug 2015 12:36:40 -0700
> >> Subject: Re: custom levels via configuration
> >> From: garydgregory@gmail.com
> >> To: log4j-user@logging.apache.org
> >> 
> >> We've never released a version "2.0-1.fc21" so it must be a Fedora build,
> >> presumably based on 2.0 or some fork of it.
> >> 
> >> You need to test with version 2.3 or a 2.4-SNAPSHOT. I'll leave you to
> >> Google how to install 2.3 on Fedora ;-)
> >> 
> >> Gary
> >> 
> >> On Wed, Aug 26, 2015 at 12:14 PM, Nicholas Duane <ni...@msn.com> wrote:
> >> 
> >>> First off let me admit that I'm a noob at both Linux and java, and log4j
> >>> for that matter.
> >>> 
> >>> I don't know how to package anything so my class that you see is a simple
> >>> java class which I compiled using javac.  I then run it using 'java
> >>> HelloWorld'.  I'm running fedora 21.  When I do a 'yum list log4j' it says
> >>> I have 2.0-1.fc21.
> >>> 
> >>> Thanks,
> >>> Nick
> >>> 
> >>>> Date: Wed, 26 Aug 2015 11:46:51 -0700
> >>>> Subject: Re: custom levels via configuration
> >>>> From: garydgregory@gmail.com
> >>>> To: log4j-user@logging.apache.org
> >>>> 
> >>>> This:
> >>>> 
> >>>> <Logger name="HelloWorld" level="ALL">
> >>>> 
> >>>> is only going to match:
> >>>> 
> >>>> static Logger log = LogManager.getLogger(HelloWorld.class.getName());
> >>>> 
> >>>> if the class in unpackaged, which it looks it is based on this paste but
> >>> I
> >>>> want to double check that you did not omit anything from the example.
> >>>> 
> >>>> Are you using the latest version (2.3)?.
> >>>> 
> >>>> I just added this test the other day to Git master:
> >>>> 
> >>>> org.apache.logging.log4j.core.CustomLevelsTest
> >>>> 
> >>>> And it shows that we can configure custom levels from a file and see them
> >>>> in code.
> >>>> 
> >>>> So I am puzzled here.
> >>>> 
> >>>> You could try the latest from Git master as well but I do not recall any
> >>>> fixes in this area.
> >>>> 
> >>>> I wonder if the Appenders are processed by the configuration _before_ the
> >>>> custom levels...
> >>>> 
> >>>> Gary
> >>>> 
> >>>> 
> >>>> On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com> wrote:
> >>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> On to my next problem.  I'm trying to define a custom level in
> >>>>> configuration.  Not sure if it's working or not.  However, when I
> >>> attempt
> >>>>> to get the level for that custom level I get back null, which I wasn't
> >>>>> expecting.  Here is the log4j2.xml config file:
> >>>>> 
> >>>>> <?xml version="1.0" encoding="UTF-8"?>
> >>>>> <Configuration status="trace" verbose="true">
> >>>>>  <CustomLevels>
> >>>>>    <CustomLevel name="INFOM1" intLevel="399"/>
> >>>>>    <CustomLevel name="INFOP1" intLevel="401"/>
> >>>>>  </CustomLevels>
> >>>>>  <Appenders>
> >>>>>    <File name="info" fileName="info.log">
> >>>>>      <PatternLayout>
> >>>>>    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> >>>>>      </PatternLayout>
> >>>>>      <Filters>
> >>>>>    <ThresholdFilter level="INFOM1" onMatch="DENY"
> >>> onMismatch="NEUTRAL"/>
> >>>>>    <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> >>>>>      </Filters>
> >>>>>    </File>
> >>>>>  </Appenders>
> >>>>>  <Loggers>
> >>>>>    <Logger name="HelloWorld" level="ALL">
> >>>>>      <AppenderRef ref="info"/>
> >>>>>    </Logger>
> >>>>>    <Root>
> >>>>>    </Root>
> >>>>>  </Loggers>
> >>>>> </Configuration>
> >>>>> 
> >>>>> Here is my code:
> >>>>> 
> >>>>> import org.apache.logging.log4j.LogManager;
> >>>>> import org.apache.logging.log4j.Logger;
> >>>>> import org.apache.logging.log4j.Level;
> >>>>> 
> >>>>> public class HelloWorld
> >>>>> {
> >>>>>    static Logger log =
> >>> LogManager.getLogger(HelloWorld.class.getName());
> >>>>> 
> >>>>>    public static void main(String[] args)
> >>>>>    {
> >>>>>      System.out.println("Hello, World");
> >>>>>      log.info("hello this is an INFO  message");
> >>>>>      log.warn("hello this is a WARN message");
> >>>>>      log.debug("hello this is a DEBUG message");
> >>>>>      Level level = Level.getLevel("INFOM1");
> >>>>>      if (level == null)
> >>>>>    System.out.println("Didn't find level INFOM1");
> >>>>>      else
> >>>>>        log.log(level, "hello this is an INFOM1 message");
> >>>>>      level = Level.getLevel("INFOP1");
> >>>>>      if (level == null)
> >>>>>    System.out.println("Didn't find level INFOP1");
> >>>>>      else
> >>>>>        log.log(level, "hello this is an INFOP1 message");
> >>>>>    }
> >>>>> }
> >>>>> 
> >>>>> Any ideas?  I obviously don't want to use Level.forName() as that will
> >>>>> create the level if it doesn't exist and I want to ensure I'm pulling
> >>> the
> >>>>> value from the configuration.
> >>>>> 
> >>>>> Thanks,
> >>>>> Nick
> >>>>> 
> >>>>> 
> >>>> 
> >>>> 
> >>>> 
> >>>> 
> >>>> --
> >>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> >>>> Java Persistence with Hibernate, Second Edition
> >>>> <http://www.manning.com/bauer3/>
> >>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> >>>> Spring Batch in Action <http://www.manning.com/templier/>
> >>>> Blog: http://garygregory.wordpress.com
> >>>> Home: http://garygregory.com/
> >>>> Tweet! http://twitter.com/GaryGregory
> >>> 
> >>> 
> >> 
> >> 
> >> 
> >> -- 
> >> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> >> Java Persistence with Hibernate, Second Edition
> >> <http://www.manning.com/bauer3/>
> >> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> >> Spring Batch in Action <http://www.manning.com/templier/>
> >> Blog: http://garygregory.wordpress.com
> >> Home: http://garygregory.com/
> >> Tweet! http://twitter.com/GaryGregory
> > 		 	   		  
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
 		 	   		  

Re: custom levels via configuration

Posted by Ralph Goers <ra...@dslextreme.com>.
Custom log levels weren’t added to Log4j 2 until version 2.1, so if the version you are using is older than that it is no surprise that it isn’t working.

Ralph

> On Aug 26, 2015, at 2:34 PM, Nicholas Duane <ni...@msn.com> wrote:
> 
> While I work on figuring out how to get a newer version of log4j2 installed I'm wondering whether there is some additional investigation I can do with the version I have.  For instance, I was hoping with the level of logging I have enabled, that log4j would be indicating some issue it had with the custom level.  However, I don't see such an issue.  The only thing I see is an issue with the custom level, which I'm guessing is when I'm using it in the filter.  I've attached the warning in the log below.
> 
> Is there some additional logging I can turn on such that log4j will produce more info which might indicate why my custom levels aren't working?  Here is my current log4j2 configuration.
> 
> log4j2.xml:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="trace" verbose="true">
>  <CustomLevels>
>    <CustomLevel name="INFOM1" intLevel="399"/>
>    <CustomLevel name="INFOP1" intLevel="401"/>
>  </CustomLevels>
>  <Appenders>
>    <File name="info" fileName="info.log">
>      <PatternLayout>
>    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
>      </PatternLayout>
>      <Filters>
>    <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
>    <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
>      </Filters>
>    </File>
>  </Appenders>
>  <Loggers>
>    <Logger name="HelloWorld" level="ALL">
>      <AppenderRef ref="info"/>
>    </Logger>
>    <Root>
>    </Root>
>  </Loggers>
> </Configuration>
> 
> snippet of console output:
> 
> 2015-08-26 14:26:21,070 WARN Error while converting string [INFOM1] to type [class org.apache.logging.log4j.Level]. Using default value [null]. java.lang.IllegalArgumentException: Unknown level constant [INFOM1].
>    at org.apache.logging.log4j.Level.valueOf(Level.java:281)
>    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:240)
>    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:237)
>    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters.convert(TypeConverters.java:343)
>    at org.apache.logging.log4j.core.config.plugins.visitors.AbstractPluginVisitor.convert(AbstractPluginVisitor.java:130)
>    at org.apache.logging.log4j.core.config.plugins.visitors.PluginAttributeVisitor.visit(PluginAttributeVisitor.java:44)
>    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.generateParameters(PluginBuilder.java:233)
>    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:131)
>    at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:748)
>    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:683)
>    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
>    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
>    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
>    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:349)
>    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:150)
>    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:358)
>    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:416)
>    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:146)
>    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:75)
>    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
>    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
>    at HelloWorld.<clinit>(HelloWorld.java:7)
> 
> Thanks,
> Nick
> 
>> Date: Wed, 26 Aug 2015 12:36:40 -0700
>> Subject: Re: custom levels via configuration
>> From: garydgregory@gmail.com
>> To: log4j-user@logging.apache.org
>> 
>> We've never released a version "2.0-1.fc21" so it must be a Fedora build,
>> presumably based on 2.0 or some fork of it.
>> 
>> You need to test with version 2.3 or a 2.4-SNAPSHOT. I'll leave you to
>> Google how to install 2.3 on Fedora ;-)
>> 
>> Gary
>> 
>> On Wed, Aug 26, 2015 at 12:14 PM, Nicholas Duane <ni...@msn.com> wrote:
>> 
>>> First off let me admit that I'm a noob at both Linux and java, and log4j
>>> for that matter.
>>> 
>>> I don't know how to package anything so my class that you see is a simple
>>> java class which I compiled using javac.  I then run it using 'java
>>> HelloWorld'.  I'm running fedora 21.  When I do a 'yum list log4j' it says
>>> I have 2.0-1.fc21.
>>> 
>>> Thanks,
>>> Nick
>>> 
>>>> Date: Wed, 26 Aug 2015 11:46:51 -0700
>>>> Subject: Re: custom levels via configuration
>>>> From: garydgregory@gmail.com
>>>> To: log4j-user@logging.apache.org
>>>> 
>>>> This:
>>>> 
>>>> <Logger name="HelloWorld" level="ALL">
>>>> 
>>>> is only going to match:
>>>> 
>>>> static Logger log = LogManager.getLogger(HelloWorld.class.getName());
>>>> 
>>>> if the class in unpackaged, which it looks it is based on this paste but
>>> I
>>>> want to double check that you did not omit anything from the example.
>>>> 
>>>> Are you using the latest version (2.3)?.
>>>> 
>>>> I just added this test the other day to Git master:
>>>> 
>>>> org.apache.logging.log4j.core.CustomLevelsTest
>>>> 
>>>> And it shows that we can configure custom levels from a file and see them
>>>> in code.
>>>> 
>>>> So I am puzzled here.
>>>> 
>>>> You could try the latest from Git master as well but I do not recall any
>>>> fixes in this area.
>>>> 
>>>> I wonder if the Appenders are processed by the configuration _before_ the
>>>> custom levels...
>>>> 
>>>> Gary
>>>> 
>>>> 
>>>> On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com> wrote:
>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> On to my next problem.  I'm trying to define a custom level in
>>>>> configuration.  Not sure if it's working or not.  However, when I
>>> attempt
>>>>> to get the level for that custom level I get back null, which I wasn't
>>>>> expecting.  Here is the log4j2.xml config file:
>>>>> 
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <Configuration status="trace" verbose="true">
>>>>>  <CustomLevels>
>>>>>    <CustomLevel name="INFOM1" intLevel="399"/>
>>>>>    <CustomLevel name="INFOP1" intLevel="401"/>
>>>>>  </CustomLevels>
>>>>>  <Appenders>
>>>>>    <File name="info" fileName="info.log">
>>>>>      <PatternLayout>
>>>>>    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
>>>>>      </PatternLayout>
>>>>>      <Filters>
>>>>>    <ThresholdFilter level="INFOM1" onMatch="DENY"
>>> onMismatch="NEUTRAL"/>
>>>>>    <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
>>>>>      </Filters>
>>>>>    </File>
>>>>>  </Appenders>
>>>>>  <Loggers>
>>>>>    <Logger name="HelloWorld" level="ALL">
>>>>>      <AppenderRef ref="info"/>
>>>>>    </Logger>
>>>>>    <Root>
>>>>>    </Root>
>>>>>  </Loggers>
>>>>> </Configuration>
>>>>> 
>>>>> Here is my code:
>>>>> 
>>>>> import org.apache.logging.log4j.LogManager;
>>>>> import org.apache.logging.log4j.Logger;
>>>>> import org.apache.logging.log4j.Level;
>>>>> 
>>>>> public class HelloWorld
>>>>> {
>>>>>    static Logger log =
>>> LogManager.getLogger(HelloWorld.class.getName());
>>>>> 
>>>>>    public static void main(String[] args)
>>>>>    {
>>>>>      System.out.println("Hello, World");
>>>>>      log.info("hello this is an INFO  message");
>>>>>      log.warn("hello this is a WARN message");
>>>>>      log.debug("hello this is a DEBUG message");
>>>>>      Level level = Level.getLevel("INFOM1");
>>>>>      if (level == null)
>>>>>    System.out.println("Didn't find level INFOM1");
>>>>>      else
>>>>>        log.log(level, "hello this is an INFOM1 message");
>>>>>      level = Level.getLevel("INFOP1");
>>>>>      if (level == null)
>>>>>    System.out.println("Didn't find level INFOP1");
>>>>>      else
>>>>>        log.log(level, "hello this is an INFOP1 message");
>>>>>    }
>>>>> }
>>>>> 
>>>>> Any ideas?  I obviously don't want to use Level.forName() as that will
>>>>> create the level if it doesn't exist and I want to ensure I'm pulling
>>> the
>>>>> value from the configuration.
>>>>> 
>>>>> Thanks,
>>>>> Nick
>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> --
>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>> Java Persistence with Hibernate, Second Edition
>>>> <http://www.manning.com/bauer3/>
>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>> Blog: http://garygregory.wordpress.com
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>> 
>>> 
>> 
>> 
>> 
>> -- 
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition
>> <http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
> 		 	   		  



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: custom levels via configuration

Posted by Gary Gregory <ga...@gmail.com>.
The current version of Log4j has more internal logging than past ones, but
maybe not in this area.

If Yum or whatever installer Fedora likes best does not do what you want,
you can download the 2.3 jars from the Log4j site and put them in your
classpath.

Gary

On Wed, Aug 26, 2015 at 2:34 PM, Nicholas Duane <ni...@msn.com> wrote:

> While I work on figuring out how to get a newer version of log4j2
> installed I'm wondering whether there is some additional investigation I
> can do with the version I have.  For instance, I was hoping with the level
> of logging I have enabled, that log4j would be indicating some issue it had
> with the custom level.  However, I don't see such an issue.  The only thing
> I see is an issue with the custom level, which I'm guessing is when I'm
> using it in the filter.  I've attached the warning in the log below.
>
> Is there some additional logging I can turn on such that log4j will
> produce more info which might indicate why my custom levels aren't
> working?  Here is my current log4j2 configuration.
>
> log4j2.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="trace" verbose="true">
>   <CustomLevels>
>     <CustomLevel name="INFOM1" intLevel="399"/>
>     <CustomLevel name="INFOP1" intLevel="401"/>
>   </CustomLevels>
>   <Appenders>
>     <File name="info" fileName="info.log">
>       <PatternLayout>
>     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
>       </PatternLayout>
>       <Filters>
>     <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
>     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
>       </Filters>
>     </File>
>   </Appenders>
>   <Loggers>
>     <Logger name="HelloWorld" level="ALL">
>       <AppenderRef ref="info"/>
>     </Logger>
>     <Root>
>     </Root>
>   </Loggers>
> </Configuration>
>
> snippet of console output:
>
> 2015-08-26 14:26:21,070 WARN Error while converting string [INFOM1] to
> type [class org.apache.logging.log4j.Level]. Using default value [null].
> java.lang.IllegalArgumentException: Unknown level constant [INFOM1].
>     at org.apache.logging.log4j.Level.valueOf(Level.java:281)
>     at
> org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:240)
>     at
> org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:237)
>     at
> org.apache.logging.log4j.core.config.plugins.util.TypeConverters.convert(TypeConverters.java:343)
>     at
> org.apache.logging.log4j.core.config.plugins.visitors.AbstractPluginVisitor.convert(AbstractPluginVisitor.java:130)
>     at
> org.apache.logging.log4j.core.config.plugins.visitors.PluginAttributeVisitor.visit(PluginAttributeVisitor.java:44)
>     at
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.generateParameters(PluginBuilder.java:233)
>     at
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:131)
>     at
> org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:748)
>     at
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:683)
>     at
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
>     at
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
>     at
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
>     at
> org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:349)
>     at
> org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:150)
>     at
> org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:358)
>     at
> org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:416)
>     at
> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:146)
>     at
> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:75)
>     at
> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
>     at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
>     at HelloWorld.<clinit>(HelloWorld.java:7)
>
> Thanks,
> Nick
>
> > Date: Wed, 26 Aug 2015 12:36:40 -0700
> > Subject: Re: custom levels via configuration
> > From: garydgregory@gmail.com
> > To: log4j-user@logging.apache.org
> >
> > We've never released a version "2.0-1.fc21" so it must be a Fedora build,
> > presumably based on 2.0 or some fork of it.
> >
> > You need to test with version 2.3 or a 2.4-SNAPSHOT. I'll leave you to
> > Google how to install 2.3 on Fedora ;-)
> >
> > Gary
> >
> > On Wed, Aug 26, 2015 at 12:14 PM, Nicholas Duane <ni...@msn.com> wrote:
> >
> > > First off let me admit that I'm a noob at both Linux and java, and
> log4j
> > > for that matter.
> > >
> > > I don't know how to package anything so my class that you see is a
> simple
> > > java class which I compiled using javac.  I then run it using 'java
> > > HelloWorld'.  I'm running fedora 21.  When I do a 'yum list log4j' it
> says
> > > I have 2.0-1.fc21.
> > >
> > > Thanks,
> > > Nick
> > >
> > > > Date: Wed, 26 Aug 2015 11:46:51 -0700
> > > > Subject: Re: custom levels via configuration
> > > > From: garydgregory@gmail.com
> > > > To: log4j-user@logging.apache.org
> > > >
> > > > This:
> > > >
> > > > <Logger name="HelloWorld" level="ALL">
> > > >
> > > > is only going to match:
> > > >
> > > > static Logger log = LogManager.getLogger(HelloWorld.class.getName());
> > > >
> > > > if the class in unpackaged, which it looks it is based on this paste
> but
> > > I
> > > > want to double check that you did not omit anything from the example.
> > > >
> > > > Are you using the latest version (2.3)?.
> > > >
> > > > I just added this test the other day to Git master:
> > > >
> > > > org.apache.logging.log4j.core.CustomLevelsTest
> > > >
> > > > And it shows that we can configure custom levels from a file and see
> them
> > > > in code.
> > > >
> > > > So I am puzzled here.
> > > >
> > > > You could try the latest from Git master as well but I do not recall
> any
> > > > fixes in this area.
> > > >
> > > > I wonder if the Appenders are processed by the configuration
> _before_ the
> > > > custom levels...
> > > >
> > > > Gary
> > > >
> > > >
> > > > On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com>
> wrote:
> > > >
> > > > >
> > > > >
> > > > >
> > > > > On to my next problem.  I'm trying to define a custom level in
> > > > > configuration.  Not sure if it's working or not.  However, when I
> > > attempt
> > > > > to get the level for that custom level I get back null, which I
> wasn't
> > > > > expecting.  Here is the log4j2.xml config file:
> > > > >
> > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > <Configuration status="trace" verbose="true">
> > > > >   <CustomLevels>
> > > > >     <CustomLevel name="INFOM1" intLevel="399"/>
> > > > >     <CustomLevel name="INFOP1" intLevel="401"/>
> > > > >   </CustomLevels>
> > > > >   <Appenders>
> > > > >     <File name="info" fileName="info.log">
> > > > >       <PatternLayout>
> > > > >     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> > > > >       </PatternLayout>
> > > > >       <Filters>
> > > > >     <ThresholdFilter level="INFOM1" onMatch="DENY"
> > > onMismatch="NEUTRAL"/>
> > > > >     <ThresholdFilter level="INFO" onMatch="ACCEPT"
> onMismatch="DENY"/>
> > > > >       </Filters>
> > > > >     </File>
> > > > >   </Appenders>
> > > > >   <Loggers>
> > > > >     <Logger name="HelloWorld" level="ALL">
> > > > >       <AppenderRef ref="info"/>
> > > > >     </Logger>
> > > > >     <Root>
> > > > >     </Root>
> > > > >   </Loggers>
> > > > > </Configuration>
> > > > >
> > > > > Here is my code:
> > > > >
> > > > > import org.apache.logging.log4j.LogManager;
> > > > > import org.apache.logging.log4j.Logger;
> > > > > import org.apache.logging.log4j.Level;
> > > > >
> > > > > public class HelloWorld
> > > > > {
> > > > >     static Logger log =
> > > LogManager.getLogger(HelloWorld.class.getName());
> > > > >
> > > > >     public static void main(String[] args)
> > > > >     {
> > > > >       System.out.println("Hello, World");
> > > > >       log.info("hello this is an INFO  message");
> > > > >       log.warn("hello this is a WARN message");
> > > > >       log.debug("hello this is a DEBUG message");
> > > > >       Level level = Level.getLevel("INFOM1");
> > > > >       if (level == null)
> > > > >     System.out.println("Didn't find level INFOM1");
> > > > >       else
> > > > >         log.log(level, "hello this is an INFOM1 message");
> > > > >       level = Level.getLevel("INFOP1");
> > > > >       if (level == null)
> > > > >     System.out.println("Didn't find level INFOP1");
> > > > >       else
> > > > >         log.log(level, "hello this is an INFOP1 message");
> > > > >     }
> > > > > }
> > > > >
> > > > > Any ideas?  I obviously don't want to use Level.forName() as that
> will
> > > > > create the level if it doesn't exist and I want to ensure I'm
> pulling
> > > the
> > > > > value from the configuration.
> > > > >
> > > > > Thanks,
> > > > > Nick
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > > > Java Persistence with Hibernate, Second Edition
> > > > <http://www.manning.com/bauer3/>
> > > > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > > > Spring Batch in Action <http://www.manning.com/templier/>
> > > > Blog: http://garygregory.wordpress.com
> > > > Home: http://garygregory.com/
> > > > Tweet! http://twitter.com/GaryGregory
> > >
> > >
> >
> >
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition
> > <http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
>
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

RE: custom levels via configuration

Posted by Nicholas Duane <ni...@msn.com>.
While I work on figuring out how to get a newer version of log4j2 installed I'm wondering whether there is some additional investigation I can do with the version I have.  For instance, I was hoping with the level of logging I have enabled, that log4j would be indicating some issue it had with the custom level.  However, I don't see such an issue.  The only thing I see is an issue with the custom level, which I'm guessing is when I'm using it in the filter.  I've attached the warning in the log below.

Is there some additional logging I can turn on such that log4j will produce more info which might indicate why my custom levels aren't working?  Here is my current log4j2 configuration.

log4j2.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" verbose="true">
  <CustomLevels>
    <CustomLevel name="INFOM1" intLevel="399"/>
    <CustomLevel name="INFOP1" intLevel="401"/>
  </CustomLevels>
  <Appenders>
    <File name="info" fileName="info.log">
      <PatternLayout>
    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
      </PatternLayout>
      <Filters>
    <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
    <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
      </Filters>
    </File>
  </Appenders>
  <Loggers>
    <Logger name="HelloWorld" level="ALL">
      <AppenderRef ref="info"/>
    </Logger>
    <Root>
    </Root>
  </Loggers>
</Configuration>

snippet of console output:

2015-08-26 14:26:21,070 WARN Error while converting string [INFOM1] to type [class org.apache.logging.log4j.Level]. Using default value [null]. java.lang.IllegalArgumentException: Unknown level constant [INFOM1].
    at org.apache.logging.log4j.Level.valueOf(Level.java:281)
    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:240)
    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters$LevelConverter.convert(TypeConverters.java:237)
    at org.apache.logging.log4j.core.config.plugins.util.TypeConverters.convert(TypeConverters.java:343)
    at org.apache.logging.log4j.core.config.plugins.visitors.AbstractPluginVisitor.convert(AbstractPluginVisitor.java:130)
    at org.apache.logging.log4j.core.config.plugins.visitors.PluginAttributeVisitor.visit(PluginAttributeVisitor.java:44)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.generateParameters(PluginBuilder.java:233)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:131)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:748)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:683)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:675)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:349)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:150)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:358)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:416)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:146)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:75)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
    at HelloWorld.<clinit>(HelloWorld.java:7)

Thanks,
Nick

> Date: Wed, 26 Aug 2015 12:36:40 -0700
> Subject: Re: custom levels via configuration
> From: garydgregory@gmail.com
> To: log4j-user@logging.apache.org
> 
> We've never released a version "2.0-1.fc21" so it must be a Fedora build,
> presumably based on 2.0 or some fork of it.
> 
> You need to test with version 2.3 or a 2.4-SNAPSHOT. I'll leave you to
> Google how to install 2.3 on Fedora ;-)
> 
> Gary
> 
> On Wed, Aug 26, 2015 at 12:14 PM, Nicholas Duane <ni...@msn.com> wrote:
> 
> > First off let me admit that I'm a noob at both Linux and java, and log4j
> > for that matter.
> >
> > I don't know how to package anything so my class that you see is a simple
> > java class which I compiled using javac.  I then run it using 'java
> > HelloWorld'.  I'm running fedora 21.  When I do a 'yum list log4j' it says
> > I have 2.0-1.fc21.
> >
> > Thanks,
> > Nick
> >
> > > Date: Wed, 26 Aug 2015 11:46:51 -0700
> > > Subject: Re: custom levels via configuration
> > > From: garydgregory@gmail.com
> > > To: log4j-user@logging.apache.org
> > >
> > > This:
> > >
> > > <Logger name="HelloWorld" level="ALL">
> > >
> > > is only going to match:
> > >
> > > static Logger log = LogManager.getLogger(HelloWorld.class.getName());
> > >
> > > if the class in unpackaged, which it looks it is based on this paste but
> > I
> > > want to double check that you did not omit anything from the example.
> > >
> > > Are you using the latest version (2.3)?.
> > >
> > > I just added this test the other day to Git master:
> > >
> > > org.apache.logging.log4j.core.CustomLevelsTest
> > >
> > > And it shows that we can configure custom levels from a file and see them
> > > in code.
> > >
> > > So I am puzzled here.
> > >
> > > You could try the latest from Git master as well but I do not recall any
> > > fixes in this area.
> > >
> > > I wonder if the Appenders are processed by the configuration _before_ the
> > > custom levels...
> > >
> > > Gary
> > >
> > >
> > > On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com> wrote:
> > >
> > > >
> > > >
> > > >
> > > > On to my next problem.  I'm trying to define a custom level in
> > > > configuration.  Not sure if it's working or not.  However, when I
> > attempt
> > > > to get the level for that custom level I get back null, which I wasn't
> > > > expecting.  Here is the log4j2.xml config file:
> > > >
> > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > <Configuration status="trace" verbose="true">
> > > >   <CustomLevels>
> > > >     <CustomLevel name="INFOM1" intLevel="399"/>
> > > >     <CustomLevel name="INFOP1" intLevel="401"/>
> > > >   </CustomLevels>
> > > >   <Appenders>
> > > >     <File name="info" fileName="info.log">
> > > >       <PatternLayout>
> > > >     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> > > >       </PatternLayout>
> > > >       <Filters>
> > > >     <ThresholdFilter level="INFOM1" onMatch="DENY"
> > onMismatch="NEUTRAL"/>
> > > >     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> > > >       </Filters>
> > > >     </File>
> > > >   </Appenders>
> > > >   <Loggers>
> > > >     <Logger name="HelloWorld" level="ALL">
> > > >       <AppenderRef ref="info"/>
> > > >     </Logger>
> > > >     <Root>
> > > >     </Root>
> > > >   </Loggers>
> > > > </Configuration>
> > > >
> > > > Here is my code:
> > > >
> > > > import org.apache.logging.log4j.LogManager;
> > > > import org.apache.logging.log4j.Logger;
> > > > import org.apache.logging.log4j.Level;
> > > >
> > > > public class HelloWorld
> > > > {
> > > >     static Logger log =
> > LogManager.getLogger(HelloWorld.class.getName());
> > > >
> > > >     public static void main(String[] args)
> > > >     {
> > > >       System.out.println("Hello, World");
> > > >       log.info("hello this is an INFO  message");
> > > >       log.warn("hello this is a WARN message");
> > > >       log.debug("hello this is a DEBUG message");
> > > >       Level level = Level.getLevel("INFOM1");
> > > >       if (level == null)
> > > >     System.out.println("Didn't find level INFOM1");
> > > >       else
> > > >         log.log(level, "hello this is an INFOM1 message");
> > > >       level = Level.getLevel("INFOP1");
> > > >       if (level == null)
> > > >     System.out.println("Didn't find level INFOP1");
> > > >       else
> > > >         log.log(level, "hello this is an INFOP1 message");
> > > >     }
> > > > }
> > > >
> > > > Any ideas?  I obviously don't want to use Level.forName() as that will
> > > > create the level if it doesn't exist and I want to ensure I'm pulling
> > the
> > > > value from the configuration.
> > > >
> > > > Thanks,
> > > > Nick
> > > >
> > > >
> > >
> > >
> > >
> > >
> > > --
> > > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > > Java Persistence with Hibernate, Second Edition
> > > <http://www.manning.com/bauer3/>
> > > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > > Spring Batch in Action <http://www.manning.com/templier/>
> > > Blog: http://garygregory.wordpress.com
> > > Home: http://garygregory.com/
> > > Tweet! http://twitter.com/GaryGregory
> >
> >
> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
 		 	   		  

Re: custom levels via configuration

Posted by Gary Gregory <ga...@gmail.com>.
We've never released a version "2.0-1.fc21" so it must be a Fedora build,
presumably based on 2.0 or some fork of it.

You need to test with version 2.3 or a 2.4-SNAPSHOT. I'll leave you to
Google how to install 2.3 on Fedora ;-)

Gary

On Wed, Aug 26, 2015 at 12:14 PM, Nicholas Duane <ni...@msn.com> wrote:

> First off let me admit that I'm a noob at both Linux and java, and log4j
> for that matter.
>
> I don't know how to package anything so my class that you see is a simple
> java class which I compiled using javac.  I then run it using 'java
> HelloWorld'.  I'm running fedora 21.  When I do a 'yum list log4j' it says
> I have 2.0-1.fc21.
>
> Thanks,
> Nick
>
> > Date: Wed, 26 Aug 2015 11:46:51 -0700
> > Subject: Re: custom levels via configuration
> > From: garydgregory@gmail.com
> > To: log4j-user@logging.apache.org
> >
> > This:
> >
> > <Logger name="HelloWorld" level="ALL">
> >
> > is only going to match:
> >
> > static Logger log = LogManager.getLogger(HelloWorld.class.getName());
> >
> > if the class in unpackaged, which it looks it is based on this paste but
> I
> > want to double check that you did not omit anything from the example.
> >
> > Are you using the latest version (2.3)?.
> >
> > I just added this test the other day to Git master:
> >
> > org.apache.logging.log4j.core.CustomLevelsTest
> >
> > And it shows that we can configure custom levels from a file and see them
> > in code.
> >
> > So I am puzzled here.
> >
> > You could try the latest from Git master as well but I do not recall any
> > fixes in this area.
> >
> > I wonder if the Appenders are processed by the configuration _before_ the
> > custom levels...
> >
> > Gary
> >
> >
> > On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com> wrote:
> >
> > >
> > >
> > >
> > > On to my next problem.  I'm trying to define a custom level in
> > > configuration.  Not sure if it's working or not.  However, when I
> attempt
> > > to get the level for that custom level I get back null, which I wasn't
> > > expecting.  Here is the log4j2.xml config file:
> > >
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <Configuration status="trace" verbose="true">
> > >   <CustomLevels>
> > >     <CustomLevel name="INFOM1" intLevel="399"/>
> > >     <CustomLevel name="INFOP1" intLevel="401"/>
> > >   </CustomLevels>
> > >   <Appenders>
> > >     <File name="info" fileName="info.log">
> > >       <PatternLayout>
> > >     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> > >       </PatternLayout>
> > >       <Filters>
> > >     <ThresholdFilter level="INFOM1" onMatch="DENY"
> onMismatch="NEUTRAL"/>
> > >     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> > >       </Filters>
> > >     </File>
> > >   </Appenders>
> > >   <Loggers>
> > >     <Logger name="HelloWorld" level="ALL">
> > >       <AppenderRef ref="info"/>
> > >     </Logger>
> > >     <Root>
> > >     </Root>
> > >   </Loggers>
> > > </Configuration>
> > >
> > > Here is my code:
> > >
> > > import org.apache.logging.log4j.LogManager;
> > > import org.apache.logging.log4j.Logger;
> > > import org.apache.logging.log4j.Level;
> > >
> > > public class HelloWorld
> > > {
> > >     static Logger log =
> LogManager.getLogger(HelloWorld.class.getName());
> > >
> > >     public static void main(String[] args)
> > >     {
> > >       System.out.println("Hello, World");
> > >       log.info("hello this is an INFO  message");
> > >       log.warn("hello this is a WARN message");
> > >       log.debug("hello this is a DEBUG message");
> > >       Level level = Level.getLevel("INFOM1");
> > >       if (level == null)
> > >     System.out.println("Didn't find level INFOM1");
> > >       else
> > >         log.log(level, "hello this is an INFOM1 message");
> > >       level = Level.getLevel("INFOP1");
> > >       if (level == null)
> > >     System.out.println("Didn't find level INFOP1");
> > >       else
> > >         log.log(level, "hello this is an INFOP1 message");
> > >     }
> > > }
> > >
> > > Any ideas?  I obviously don't want to use Level.forName() as that will
> > > create the level if it doesn't exist and I want to ensure I'm pulling
> the
> > > value from the configuration.
> > >
> > > Thanks,
> > > Nick
> > >
> > >
> >
> >
> >
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition
> > <http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
>
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

RE: custom levels via configuration

Posted by Nicholas Duane <ni...@msn.com>.
First off let me admit that I'm a noob at both Linux and java, and log4j for that matter.
 
I don't know how to package anything so my class that you see is a simple java class which I compiled using javac.  I then run it using 'java HelloWorld'.  I'm running fedora 21.  When I do a 'yum list log4j' it says I have 2.0-1.fc21.
 
Thanks,
Nick
 
> Date: Wed, 26 Aug 2015 11:46:51 -0700
> Subject: Re: custom levels via configuration
> From: garydgregory@gmail.com
> To: log4j-user@logging.apache.org
> 
> This:
> 
> <Logger name="HelloWorld" level="ALL">
> 
> is only going to match:
> 
> static Logger log = LogManager.getLogger(HelloWorld.class.getName());
> 
> if the class in unpackaged, which it looks it is based on this paste but I
> want to double check that you did not omit anything from the example.
> 
> Are you using the latest version (2.3)?.
> 
> I just added this test the other day to Git master:
> 
> org.apache.logging.log4j.core.CustomLevelsTest
> 
> And it shows that we can configure custom levels from a file and see them
> in code.
> 
> So I am puzzled here.
> 
> You could try the latest from Git master as well but I do not recall any
> fixes in this area.
> 
> I wonder if the Appenders are processed by the configuration _before_ the
> custom levels...
> 
> Gary
> 
> 
> On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com> wrote:
> 
> >
> >
> >
> > On to my next problem.  I'm trying to define a custom level in
> > configuration.  Not sure if it's working or not.  However, when I attempt
> > to get the level for that custom level I get back null, which I wasn't
> > expecting.  Here is the log4j2.xml config file:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <Configuration status="trace" verbose="true">
> >   <CustomLevels>
> >     <CustomLevel name="INFOM1" intLevel="399"/>
> >     <CustomLevel name="INFOP1" intLevel="401"/>
> >   </CustomLevels>
> >   <Appenders>
> >     <File name="info" fileName="info.log">
> >       <PatternLayout>
> >     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> >       </PatternLayout>
> >       <Filters>
> >     <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
> >     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> >       </Filters>
> >     </File>
> >   </Appenders>
> >   <Loggers>
> >     <Logger name="HelloWorld" level="ALL">
> >       <AppenderRef ref="info"/>
> >     </Logger>
> >     <Root>
> >     </Root>
> >   </Loggers>
> > </Configuration>
> >
> > Here is my code:
> >
> > import org.apache.logging.log4j.LogManager;
> > import org.apache.logging.log4j.Logger;
> > import org.apache.logging.log4j.Level;
> >
> > public class HelloWorld
> > {
> >     static Logger log = LogManager.getLogger(HelloWorld.class.getName());
> >
> >     public static void main(String[] args)
> >     {
> >       System.out.println("Hello, World");
> >       log.info("hello this is an INFO  message");
> >       log.warn("hello this is a WARN message");
> >       log.debug("hello this is a DEBUG message");
> >       Level level = Level.getLevel("INFOM1");
> >       if (level == null)
> >     System.out.println("Didn't find level INFOM1");
> >       else
> >         log.log(level, "hello this is an INFOM1 message");
> >       level = Level.getLevel("INFOP1");
> >       if (level == null)
> >     System.out.println("Didn't find level INFOP1");
> >       else
> >         log.log(level, "hello this is an INFOP1 message");
> >     }
> > }
> >
> > Any ideas?  I obviously don't want to use Level.forName() as that will
> > create the level if it doesn't exist and I want to ensure I'm pulling the
> > value from the configuration.
> >
> > Thanks,
> > Nick
> >
> >
> 
> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
 		 	   		  

Re: custom levels via configuration

Posted by Gary Gregory <ga...@gmail.com>.
Start reading here:

- Main site: https://logging.apache.org/log4j/2.x/
- Source code: https://logging.apache.org/log4j/2.x/source-repository.html
- This ML

Git is the source control system we use.

Git master refers to the main branch of development with Git.

Gary


On Wed, Aug 26, 2015 at 12:54 PM, Nicholas Duane <ni...@msn.com> wrote:

> Yes I am a true noob to java and linux and log4j.
>
> What is gitmaster?  I assume related to github somehow?  How can I see the
> test you created?  Is there a link you can provide?
>
> Thanks,
> Nick
>
> > Date: Wed, 26 Aug 2015 12:34:45 -0700
> > Subject: Re: custom levels via configuration
> > From: garydgregory@gmail.com
> > To: log4j-user@logging.apache.org
> >
> > On Wed, Aug 26, 2015 at 11:46 AM, Gary Gregory <ga...@gmail.com>
> > wrote:
> >
> > > This:
> > >
> > > <Logger name="HelloWorld" level="ALL">
> > >
> > > is only going to match:
> > >
> > > static Logger log = LogManager.getLogger(HelloWorld.class.getName());
> > >
> > > if the class in unpackaged, which it looks it is based on this paste
> but I
> > > want to double check that you did not omit anything from the example.
> > >
> > > Are you using the latest version (2.3)?.
> > >
> > > I just added this test the other day to Git master:
> > >
> > > org.apache.logging.log4j.core.CustomLevelsTest
> > >
> > > And it shows that we can configure custom levels from a file and see
> them
> > > in code.
> > >
> > > So I am puzzled here.
> > >
> > > You could try the latest from Git master as well but I do not recall
> any
> > > fixes in this area.
> > >
> > > I wonder if the Appenders are processed by the configuration _before_
> the
> > > custom levels...
> > >
> >
> > My above suspicion was unfounded, see my new
> > test org.apache.logging.log4j.core.CustomLevelsWithFiltersTest and feel
> > free to provide a patch to test your desired behavior. This might be a
> tall
> > order if you are a true Java newbie ;-)
> >
> > Gary
> >
> > >
> > > Gary
> > >
> > >
> > > On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com>
> wrote:
> > >
> > >>
> > >>
> > >>
> > >> On to my next problem.  I'm trying to define a custom level in
> > >> configuration.  Not sure if it's working or not.  However, when I
> attempt
> > >> to get the level for that custom level I get back null, which I wasn't
> > >> expecting.  Here is the log4j2.xml config file:
> > >>
> > >> <?xml version="1.0" encoding="UTF-8"?>
> > >> <Configuration status="trace" verbose="true">
> > >>   <CustomLevels>
> > >>     <CustomLevel name="INFOM1" intLevel="399"/>
> > >>     <CustomLevel name="INFOP1" intLevel="401"/>
> > >>   </CustomLevels>
> > >>   <Appenders>
> > >>     <File name="info" fileName="info.log">
> > >>       <PatternLayout>
> > >>     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> > >>       </PatternLayout>
> > >>       <Filters>
> > >>     <ThresholdFilter level="INFOM1" onMatch="DENY"
> onMismatch="NEUTRAL"/>
> > >>     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> > >>       </Filters>
> > >>     </File>
> > >>   </Appenders>
> > >>   <Loggers>
> > >>     <Logger name="HelloWorld" level="ALL">
> > >>       <AppenderRef ref="info"/>
> > >>     </Logger>
> > >>     <Root>
> > >>     </Root>
> > >>   </Loggers>
> > >> </Configuration>
> > >>
> > >> Here is my code:
> > >>
> > >> import org.apache.logging.log4j.LogManager;
> > >> import org.apache.logging.log4j.Logger;
> > >> import org.apache.logging.log4j.Level;
> > >>
> > >> public class HelloWorld
> > >> {
> > >>     static Logger log =
> LogManager.getLogger(HelloWorld.class.getName());
> > >>
> > >>     public static void main(String[] args)
> > >>     {
> > >>       System.out.println("Hello, World");
> > >>       log.info("hello this is an INFO  message");
> > >>       log.warn("hello this is a WARN message");
> > >>       log.debug("hello this is a DEBUG message");
> > >>       Level level = Level.getLevel("INFOM1");
> > >>       if (level == null)
> > >>     System.out.println("Didn't find level INFOM1");
> > >>       else
> > >>         log.log(level, "hello this is an INFOM1 message");
> > >>       level = Level.getLevel("INFOP1");
> > >>       if (level == null)
> > >>     System.out.println("Didn't find level INFOP1");
> > >>       else
> > >>         log.log(level, "hello this is an INFOP1 message");
> > >>     }
> > >> }
> > >>
> > >> Any ideas?  I obviously don't want to use Level.forName() as that will
> > >> create the level if it doesn't exist and I want to ensure I'm pulling
> the
> > >> value from the configuration.
> > >>
> > >> Thanks,
> > >> Nick
> > >>
> > >>
> > >
> > >
> > >
> > >
> > > --
> > > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > > Java Persistence with Hibernate, Second Edition
> > > <http://www.manning.com/bauer3/>
> > > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > > Spring Batch in Action <http://www.manning.com/templier/>
> > > Blog: http://garygregory.wordpress.com
> > > Home: http://garygregory.com/
> > > Tweet! http://twitter.com/GaryGregory
> > >
> >
> >
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition
> > <http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
>
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

RE: custom levels via configuration

Posted by Nicholas Duane <ni...@msn.com>.
Yes I am a true noob to java and linux and log4j.

What is gitmaster?  I assume related to github somehow?  How can I see the test you created?  Is there a link you can provide?

Thanks,
Nick

> Date: Wed, 26 Aug 2015 12:34:45 -0700
> Subject: Re: custom levels via configuration
> From: garydgregory@gmail.com
> To: log4j-user@logging.apache.org
> 
> On Wed, Aug 26, 2015 at 11:46 AM, Gary Gregory <ga...@gmail.com>
> wrote:
> 
> > This:
> >
> > <Logger name="HelloWorld" level="ALL">
> >
> > is only going to match:
> >
> > static Logger log = LogManager.getLogger(HelloWorld.class.getName());
> >
> > if the class in unpackaged, which it looks it is based on this paste but I
> > want to double check that you did not omit anything from the example.
> >
> > Are you using the latest version (2.3)?.
> >
> > I just added this test the other day to Git master:
> >
> > org.apache.logging.log4j.core.CustomLevelsTest
> >
> > And it shows that we can configure custom levels from a file and see them
> > in code.
> >
> > So I am puzzled here.
> >
> > You could try the latest from Git master as well but I do not recall any
> > fixes in this area.
> >
> > I wonder if the Appenders are processed by the configuration _before_ the
> > custom levels...
> >
> 
> My above suspicion was unfounded, see my new
> test org.apache.logging.log4j.core.CustomLevelsWithFiltersTest and feel
> free to provide a patch to test your desired behavior. This might be a tall
> order if you are a true Java newbie ;-)
> 
> Gary
> 
> >
> > Gary
> >
> >
> > On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com> wrote:
> >
> >>
> >>
> >>
> >> On to my next problem.  I'm trying to define a custom level in
> >> configuration.  Not sure if it's working or not.  However, when I attempt
> >> to get the level for that custom level I get back null, which I wasn't
> >> expecting.  Here is the log4j2.xml config file:
> >>
> >> <?xml version="1.0" encoding="UTF-8"?>
> >> <Configuration status="trace" verbose="true">
> >>   <CustomLevels>
> >>     <CustomLevel name="INFOM1" intLevel="399"/>
> >>     <CustomLevel name="INFOP1" intLevel="401"/>
> >>   </CustomLevels>
> >>   <Appenders>
> >>     <File name="info" fileName="info.log">
> >>       <PatternLayout>
> >>     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> >>       </PatternLayout>
> >>       <Filters>
> >>     <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
> >>     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> >>       </Filters>
> >>     </File>
> >>   </Appenders>
> >>   <Loggers>
> >>     <Logger name="HelloWorld" level="ALL">
> >>       <AppenderRef ref="info"/>
> >>     </Logger>
> >>     <Root>
> >>     </Root>
> >>   </Loggers>
> >> </Configuration>
> >>
> >> Here is my code:
> >>
> >> import org.apache.logging.log4j.LogManager;
> >> import org.apache.logging.log4j.Logger;
> >> import org.apache.logging.log4j.Level;
> >>
> >> public class HelloWorld
> >> {
> >>     static Logger log = LogManager.getLogger(HelloWorld.class.getName());
> >>
> >>     public static void main(String[] args)
> >>     {
> >>       System.out.println("Hello, World");
> >>       log.info("hello this is an INFO  message");
> >>       log.warn("hello this is a WARN message");
> >>       log.debug("hello this is a DEBUG message");
> >>       Level level = Level.getLevel("INFOM1");
> >>       if (level == null)
> >>     System.out.println("Didn't find level INFOM1");
> >>       else
> >>         log.log(level, "hello this is an INFOM1 message");
> >>       level = Level.getLevel("INFOP1");
> >>       if (level == null)
> >>     System.out.println("Didn't find level INFOP1");
> >>       else
> >>         log.log(level, "hello this is an INFOP1 message");
> >>     }
> >> }
> >>
> >> Any ideas?  I obviously don't want to use Level.forName() as that will
> >> create the level if it doesn't exist and I want to ensure I'm pulling the
> >> value from the configuration.
> >>
> >> Thanks,
> >> Nick
> >>
> >>
> >
> >
> >
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition
> > <http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
> >
> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
 		 	   		  

Re: custom levels via configuration

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Aug 26, 2015 at 11:46 AM, Gary Gregory <ga...@gmail.com>
wrote:

> This:
>
> <Logger name="HelloWorld" level="ALL">
>
> is only going to match:
>
> static Logger log = LogManager.getLogger(HelloWorld.class.getName());
>
> if the class in unpackaged, which it looks it is based on this paste but I
> want to double check that you did not omit anything from the example.
>
> Are you using the latest version (2.3)?.
>
> I just added this test the other day to Git master:
>
> org.apache.logging.log4j.core.CustomLevelsTest
>
> And it shows that we can configure custom levels from a file and see them
> in code.
>
> So I am puzzled here.
>
> You could try the latest from Git master as well but I do not recall any
> fixes in this area.
>
> I wonder if the Appenders are processed by the configuration _before_ the
> custom levels...
>

My above suspicion was unfounded, see my new
test org.apache.logging.log4j.core.CustomLevelsWithFiltersTest and feel
free to provide a patch to test your desired behavior. This might be a tall
order if you are a true Java newbie ;-)

Gary

>
> Gary
>
>
> On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com> wrote:
>
>>
>>
>>
>> On to my next problem.  I'm trying to define a custom level in
>> configuration.  Not sure if it's working or not.  However, when I attempt
>> to get the level for that custom level I get back null, which I wasn't
>> expecting.  Here is the log4j2.xml config file:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <Configuration status="trace" verbose="true">
>>   <CustomLevels>
>>     <CustomLevel name="INFOM1" intLevel="399"/>
>>     <CustomLevel name="INFOP1" intLevel="401"/>
>>   </CustomLevels>
>>   <Appenders>
>>     <File name="info" fileName="info.log">
>>       <PatternLayout>
>>     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
>>       </PatternLayout>
>>       <Filters>
>>     <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
>>     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
>>       </Filters>
>>     </File>
>>   </Appenders>
>>   <Loggers>
>>     <Logger name="HelloWorld" level="ALL">
>>       <AppenderRef ref="info"/>
>>     </Logger>
>>     <Root>
>>     </Root>
>>   </Loggers>
>> </Configuration>
>>
>> Here is my code:
>>
>> import org.apache.logging.log4j.LogManager;
>> import org.apache.logging.log4j.Logger;
>> import org.apache.logging.log4j.Level;
>>
>> public class HelloWorld
>> {
>>     static Logger log = LogManager.getLogger(HelloWorld.class.getName());
>>
>>     public static void main(String[] args)
>>     {
>>       System.out.println("Hello, World");
>>       log.info("hello this is an INFO  message");
>>       log.warn("hello this is a WARN message");
>>       log.debug("hello this is a DEBUG message");
>>       Level level = Level.getLevel("INFOM1");
>>       if (level == null)
>>     System.out.println("Didn't find level INFOM1");
>>       else
>>         log.log(level, "hello this is an INFOM1 message");
>>       level = Level.getLevel("INFOP1");
>>       if (level == null)
>>     System.out.println("Didn't find level INFOP1");
>>       else
>>         log.log(level, "hello this is an INFOP1 message");
>>     }
>> }
>>
>> Any ideas?  I obviously don't want to use Level.forName() as that will
>> create the level if it doesn't exist and I want to ensure I'm pulling the
>> value from the configuration.
>>
>> Thanks,
>> Nick
>>
>>
>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: custom levels via configuration

Posted by Gary Gregory <ga...@gmail.com>.
This:

<Logger name="HelloWorld" level="ALL">

is only going to match:

static Logger log = LogManager.getLogger(HelloWorld.class.getName());

if the class in unpackaged, which it looks it is based on this paste but I
want to double check that you did not omit anything from the example.

Are you using the latest version (2.3)?.

I just added this test the other day to Git master:

org.apache.logging.log4j.core.CustomLevelsTest

And it shows that we can configure custom levels from a file and see them
in code.

So I am puzzled here.

You could try the latest from Git master as well but I do not recall any
fixes in this area.

I wonder if the Appenders are processed by the configuration _before_ the
custom levels...

Gary


On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane <ni...@msn.com> wrote:

>
>
>
> On to my next problem.  I'm trying to define a custom level in
> configuration.  Not sure if it's working or not.  However, when I attempt
> to get the level for that custom level I get back null, which I wasn't
> expecting.  Here is the log4j2.xml config file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="trace" verbose="true">
>   <CustomLevels>
>     <CustomLevel name="INFOM1" intLevel="399"/>
>     <CustomLevel name="INFOP1" intLevel="401"/>
>   </CustomLevels>
>   <Appenders>
>     <File name="info" fileName="info.log">
>       <PatternLayout>
>     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
>       </PatternLayout>
>       <Filters>
>     <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
>     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
>       </Filters>
>     </File>
>   </Appenders>
>   <Loggers>
>     <Logger name="HelloWorld" level="ALL">
>       <AppenderRef ref="info"/>
>     </Logger>
>     <Root>
>     </Root>
>   </Loggers>
> </Configuration>
>
> Here is my code:
>
> import org.apache.logging.log4j.LogManager;
> import org.apache.logging.log4j.Logger;
> import org.apache.logging.log4j.Level;
>
> public class HelloWorld
> {
>     static Logger log = LogManager.getLogger(HelloWorld.class.getName());
>
>     public static void main(String[] args)
>     {
>       System.out.println("Hello, World");
>       log.info("hello this is an INFO  message");
>       log.warn("hello this is a WARN message");
>       log.debug("hello this is a DEBUG message");
>       Level level = Level.getLevel("INFOM1");
>       if (level == null)
>     System.out.println("Didn't find level INFOM1");
>       else
>         log.log(level, "hello this is an INFOM1 message");
>       level = Level.getLevel("INFOP1");
>       if (level == null)
>     System.out.println("Didn't find level INFOP1");
>       else
>         log.log(level, "hello this is an INFOP1 message");
>     }
> }
>
> Any ideas?  I obviously don't want to use Level.forName() as that will
> create the level if it doesn't exist and I want to ensure I'm pulling the
> value from the configuration.
>
> Thanks,
> Nick
>
>




-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

RE: custom levels via configuration

Posted by Nicholas Duane <ni...@msn.com>.
It seems my custom levels aren't working as I'm getting null from Level.getLevel() when passing those custom level names.
 
Thanks,
Nick
 
> Date: Thu, 27 Aug 2015 08:34:43 +0900
> Subject: Re: custom levels via configuration
> From: remko.popma@gmail.com
> To: log4j-user@logging.apache.org
> 
> I don't have time to investigate now, but it looks like our support for
> CustomLevels is not implemented in ThresholdFilter yet.
> 
> If you use a custom level in your logger config it should work. For example:
> <loggers>
>   <root level="INFOP1">
>     <appenderref ref="file" level="INFOM1" />
> ...
> 
> Remko
> 
> 
> 
> On Thu, Aug 27, 2015 at 8:22 AM, Nicholas Duane <ni...@msn.com> wrote:
> 
> > Both were not found from my HelloClass.  And I had sent out some log4j
> > logging in where there was a warning which I assume was related to me using
> > INFOM1 in the threshold filter.
> >
> > Thanks,
> > Nick
> >
> > > Date: Thu, 27 Aug 2015 08:20:20 +0900
> > > Subject: Re: custom levels via configuration
> > > From: remko.popma@gmail.com
> > > To: log4j-user@logging.apache.org
> > >
> > > Nick,
> > >
> > > What was the output of this program? Were both INFOM1 and INFOP1 not
> > found,
> > > or was INFOM1 found (because it is used in the ThresholdFilter), but not
> > > INFOP1?
> > >
> > > Remko
> > >
> > > On Thu, Aug 27, 2015 at 3:19 AM, Nicholas Duane <ni...@msn.com> wrote:
> > >
> > > >
> > > >
> > > >
> > > > On to my next problem.  I'm trying to define a custom level in
> > > > configuration.  Not sure if it's working or not.  However, when I
> > attempt
> > > > to get the level for that custom level I get back null, which I wasn't
> > > > expecting.  Here is the log4j2.xml config file:
> > > >
> > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > <Configuration status="trace" verbose="true">
> > > >   <CustomLevels>
> > > >     <CustomLevel name="INFOM1" intLevel="399"/>
> > > >     <CustomLevel name="INFOP1" intLevel="401"/>
> > > >   </CustomLevels>
> > > >   <Appenders>
> > > >     <File name="info" fileName="info.log">
> > > >       <PatternLayout>
> > > >     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> > > >       </PatternLayout>
> > > >       <Filters>
> > > >     <ThresholdFilter level="INFOM1" onMatch="DENY"
> > onMismatch="NEUTRAL"/>
> > > >     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> > > >       </Filters>
> > > >     </File>
> > > >   </Appenders>
> > > >   <Loggers>
> > > >     <Logger name="HelloWorld" level="ALL">
> > > >       <AppenderRef ref="info"/>
> > > >     </Logger>
> > > >     <Root>
> > > >     </Root>
> > > >   </Loggers>
> > > > </Configuration>
> > > >
> > > > Here is my code:
> > > >
> > > > import org.apache.logging.log4j.LogManager;
> > > > import org.apache.logging.log4j.Logger;
> > > > import org.apache.logging.log4j.Level;
> > > >
> > > > public class HelloWorld
> > > > {
> > > >     static Logger log =
> > LogManager.getLogger(HelloWorld.class.getName());
> > > >
> > > >     public static void main(String[] args)
> > > >     {
> > > >       System.out.println("Hello, World");
> > > >       log.info("hello this is an INFO  message");
> > > >       log.warn("hello this is a WARN message");
> > > >       log.debug("hello this is a DEBUG message");
> > > >       Level level = Level.getLevel("INFOM1");
> > > >       if (level == null)
> > > >     System.out.println("Didn't find level INFOM1");
> > > >       else
> > > >         log.log(level, "hello this is an INFOM1 message");
> > > >       level = Level.getLevel("INFOP1");
> > > >       if (level == null)
> > > >     System.out.println("Didn't find level INFOP1");
> > > >       else
> > > >         log.log(level, "hello this is an INFOP1 message");
> > > >     }
> > > > }
> > > >
> > > > Any ideas?  I obviously don't want to use Level.forName() as that will
> > > > create the level if it doesn't exist and I want to ensure I'm pulling
> > the
> > > > value from the configuration.
> > > >
> > > > Thanks,
> > > > Nick
> > > >
> > > >
> >
> >
 		 	   		  

Re: custom levels via configuration

Posted by Remko Popma <re...@gmail.com>.
I don't have time to investigate now, but it looks like our support for
CustomLevels is not implemented in ThresholdFilter yet.

If you use a custom level in your logger config it should work. For example:
<loggers>
  <root level="INFOP1">
    <appenderref ref="file" level="INFOM1" />
...

Remko



On Thu, Aug 27, 2015 at 8:22 AM, Nicholas Duane <ni...@msn.com> wrote:

> Both were not found from my HelloClass.  And I had sent out some log4j
> logging in where there was a warning which I assume was related to me using
> INFOM1 in the threshold filter.
>
> Thanks,
> Nick
>
> > Date: Thu, 27 Aug 2015 08:20:20 +0900
> > Subject: Re: custom levels via configuration
> > From: remko.popma@gmail.com
> > To: log4j-user@logging.apache.org
> >
> > Nick,
> >
> > What was the output of this program? Were both INFOM1 and INFOP1 not
> found,
> > or was INFOM1 found (because it is used in the ThresholdFilter), but not
> > INFOP1?
> >
> > Remko
> >
> > On Thu, Aug 27, 2015 at 3:19 AM, Nicholas Duane <ni...@msn.com> wrote:
> >
> > >
> > >
> > >
> > > On to my next problem.  I'm trying to define a custom level in
> > > configuration.  Not sure if it's working or not.  However, when I
> attempt
> > > to get the level for that custom level I get back null, which I wasn't
> > > expecting.  Here is the log4j2.xml config file:
> > >
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <Configuration status="trace" verbose="true">
> > >   <CustomLevels>
> > >     <CustomLevel name="INFOM1" intLevel="399"/>
> > >     <CustomLevel name="INFOP1" intLevel="401"/>
> > >   </CustomLevels>
> > >   <Appenders>
> > >     <File name="info" fileName="info.log">
> > >       <PatternLayout>
> > >     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> > >       </PatternLayout>
> > >       <Filters>
> > >     <ThresholdFilter level="INFOM1" onMatch="DENY"
> onMismatch="NEUTRAL"/>
> > >     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> > >       </Filters>
> > >     </File>
> > >   </Appenders>
> > >   <Loggers>
> > >     <Logger name="HelloWorld" level="ALL">
> > >       <AppenderRef ref="info"/>
> > >     </Logger>
> > >     <Root>
> > >     </Root>
> > >   </Loggers>
> > > </Configuration>
> > >
> > > Here is my code:
> > >
> > > import org.apache.logging.log4j.LogManager;
> > > import org.apache.logging.log4j.Logger;
> > > import org.apache.logging.log4j.Level;
> > >
> > > public class HelloWorld
> > > {
> > >     static Logger log =
> LogManager.getLogger(HelloWorld.class.getName());
> > >
> > >     public static void main(String[] args)
> > >     {
> > >       System.out.println("Hello, World");
> > >       log.info("hello this is an INFO  message");
> > >       log.warn("hello this is a WARN message");
> > >       log.debug("hello this is a DEBUG message");
> > >       Level level = Level.getLevel("INFOM1");
> > >       if (level == null)
> > >     System.out.println("Didn't find level INFOM1");
> > >       else
> > >         log.log(level, "hello this is an INFOM1 message");
> > >       level = Level.getLevel("INFOP1");
> > >       if (level == null)
> > >     System.out.println("Didn't find level INFOP1");
> > >       else
> > >         log.log(level, "hello this is an INFOP1 message");
> > >     }
> > > }
> > >
> > > Any ideas?  I obviously don't want to use Level.forName() as that will
> > > create the level if it doesn't exist and I want to ensure I'm pulling
> the
> > > value from the configuration.
> > >
> > > Thanks,
> > > Nick
> > >
> > >
>
>

RE: custom levels via configuration

Posted by Nicholas Duane <ni...@msn.com>.
Both were not found from my HelloClass.  And I had sent out some log4j logging in where there was a warning which I assume was related to me using INFOM1 in the threshold filter.
 
Thanks,
Nick
 
> Date: Thu, 27 Aug 2015 08:20:20 +0900
> Subject: Re: custom levels via configuration
> From: remko.popma@gmail.com
> To: log4j-user@logging.apache.org
> 
> Nick,
> 
> What was the output of this program? Were both INFOM1 and INFOP1 not found,
> or was INFOM1 found (because it is used in the ThresholdFilter), but not
> INFOP1?
> 
> Remko
> 
> On Thu, Aug 27, 2015 at 3:19 AM, Nicholas Duane <ni...@msn.com> wrote:
> 
> >
> >
> >
> > On to my next problem.  I'm trying to define a custom level in
> > configuration.  Not sure if it's working or not.  However, when I attempt
> > to get the level for that custom level I get back null, which I wasn't
> > expecting.  Here is the log4j2.xml config file:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <Configuration status="trace" verbose="true">
> >   <CustomLevels>
> >     <CustomLevel name="INFOM1" intLevel="399"/>
> >     <CustomLevel name="INFOP1" intLevel="401"/>
> >   </CustomLevels>
> >   <Appenders>
> >     <File name="info" fileName="info.log">
> >       <PatternLayout>
> >     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> >       </PatternLayout>
> >       <Filters>
> >     <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
> >     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
> >       </Filters>
> >     </File>
> >   </Appenders>
> >   <Loggers>
> >     <Logger name="HelloWorld" level="ALL">
> >       <AppenderRef ref="info"/>
> >     </Logger>
> >     <Root>
> >     </Root>
> >   </Loggers>
> > </Configuration>
> >
> > Here is my code:
> >
> > import org.apache.logging.log4j.LogManager;
> > import org.apache.logging.log4j.Logger;
> > import org.apache.logging.log4j.Level;
> >
> > public class HelloWorld
> > {
> >     static Logger log = LogManager.getLogger(HelloWorld.class.getName());
> >
> >     public static void main(String[] args)
> >     {
> >       System.out.println("Hello, World");
> >       log.info("hello this is an INFO  message");
> >       log.warn("hello this is a WARN message");
> >       log.debug("hello this is a DEBUG message");
> >       Level level = Level.getLevel("INFOM1");
> >       if (level == null)
> >     System.out.println("Didn't find level INFOM1");
> >       else
> >         log.log(level, "hello this is an INFOM1 message");
> >       level = Level.getLevel("INFOP1");
> >       if (level == null)
> >     System.out.println("Didn't find level INFOP1");
> >       else
> >         log.log(level, "hello this is an INFOP1 message");
> >     }
> > }
> >
> > Any ideas?  I obviously don't want to use Level.forName() as that will
> > create the level if it doesn't exist and I want to ensure I'm pulling the
> > value from the configuration.
> >
> > Thanks,
> > Nick
> >
> >
 		 	   		  

Re: custom levels via configuration

Posted by Remko Popma <re...@gmail.com>.
Nick,

What was the output of this program? Were both INFOM1 and INFOP1 not found,
or was INFOM1 found (because it is used in the ThresholdFilter), but not
INFOP1?

Remko

On Thu, Aug 27, 2015 at 3:19 AM, Nicholas Duane <ni...@msn.com> wrote:

>
>
>
> On to my next problem.  I'm trying to define a custom level in
> configuration.  Not sure if it's working or not.  However, when I attempt
> to get the level for that custom level I get back null, which I wasn't
> expecting.  Here is the log4j2.xml config file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="trace" verbose="true">
>   <CustomLevels>
>     <CustomLevel name="INFOM1" intLevel="399"/>
>     <CustomLevel name="INFOP1" intLevel="401"/>
>   </CustomLevels>
>   <Appenders>
>     <File name="info" fileName="info.log">
>       <PatternLayout>
>     <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
>       </PatternLayout>
>       <Filters>
>     <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL"/>
>     <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
>       </Filters>
>     </File>
>   </Appenders>
>   <Loggers>
>     <Logger name="HelloWorld" level="ALL">
>       <AppenderRef ref="info"/>
>     </Logger>
>     <Root>
>     </Root>
>   </Loggers>
> </Configuration>
>
> Here is my code:
>
> import org.apache.logging.log4j.LogManager;
> import org.apache.logging.log4j.Logger;
> import org.apache.logging.log4j.Level;
>
> public class HelloWorld
> {
>     static Logger log = LogManager.getLogger(HelloWorld.class.getName());
>
>     public static void main(String[] args)
>     {
>       System.out.println("Hello, World");
>       log.info("hello this is an INFO  message");
>       log.warn("hello this is a WARN message");
>       log.debug("hello this is a DEBUG message");
>       Level level = Level.getLevel("INFOM1");
>       if (level == null)
>     System.out.println("Didn't find level INFOM1");
>       else
>         log.log(level, "hello this is an INFOM1 message");
>       level = Level.getLevel("INFOP1");
>       if (level == null)
>     System.out.println("Didn't find level INFOP1");
>       else
>         log.log(level, "hello this is an INFOP1 message");
>     }
> }
>
> Any ideas?  I obviously don't want to use Level.forName() as that will
> create the level if it doesn't exist and I want to ensure I'm pulling the
> value from the configuration.
>
> Thanks,
> Nick
>
>