logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: custom levels via configuration
Date Wed, 26 Aug 2015 20:30:42 GMT
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 <nickdu@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 <garydgregory@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 <nickdu@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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message