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 <[email protected]> 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: [email protected]
> > To: [email protected]
> >
> > 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 <[email protected]> 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
> > >
> > >
>
>