On Fri, Aug 2, 2013 at 5:51 PM, Ralph Goers <ralph.go...@dslextreme.com>wrote:
> We definitely need more examples. Creating some sample code might also > spur us to simplify APIs where we can. > I bet! That's a great idea. Gary > > Ralph > > > On Aug 2, 2013, at 2:38 PM, Gary Gregory wrote: > > > Does any of this belong in the 'extending log4j' section of the manual? > The > > Javadoc? > > > > Gary > > > > > > On Fri, Aug 2, 2013 at 8:30 AM, Christian Grobmeier <grobme...@gmail.com > >wrote: > > > >> Hi, > >> > >> I looked at it (Simone provided me a patch with the current state of > work). > >> > >> You need to override this in the OnamiConfigurationFactory: > >> > >> @Override > >> public Configuration getConfiguration(final String name, final URI > >> configLocation) { > >> return getConfiguration(null); > >> } > >> > >> The problem is that you need a configLocation otherwise you will be > >> returned null which causes the NPE: > >> > >> LoggerContext line 369 in beta-8: > >> final Configuration instance = > >> ConfigurationFactory.getInstance().getConfiguration(name, > >> configLocation) > >> > >> This is of course unfortunate. I have debugged the whole configuration > >> and think its very difficult > >> to programmatically configure log4j without using a xml/json file. If > >> we have a chance to make configuration easier, > >> we should do it. > >> > >> Others: are there any plans / ideas for it already? > >> > >> Cheers > >> Christian > >> > >> > >> On Fri, Aug 2, 2013 at 10:52 AM, Simone Tripodi > >> <simonetrip...@apache.org> wrote: > >>> Hi all mates, > >>> > >>> I am trying to setup log4j2 configuration programmatically, I defined > >>> my version of Configuration: > >>> > >>> > >> > +------------------------------------------------------------------------------------------------------------------------------------+ > >>> class MyLoggingConfiguration > >>> extends BaseConfiguration > >>> { > >>> > >>> private final String levelName; > >>> > >>> private final String pattern; > >>> > >>> public MyLoggingConfiguration( String levelName, String pattern ) > >>> { > >>> this.levelName = levelName; > >>> this.pattern = pattern; > >>> } > >>> > >>> @Override > >>> protected void doConfigure() > >>> { > >>> setName( "my" ); > >>> > >>> Layout<? extends Serializable> layout = createLayout( pattern, > >>> null, null, null, null ); > >>> Appender<? extends Serializable> appender = createAppender( > >>> layout, null, "SYSTEM_OUT", "Console", "false", "true" ); > >>> appender.start(); > >>> addAppender( appender ); > >>> getRootLogger().addAppender( appender, null, null ); > >>> > >>> Level level = Level.valueOf( levelName ); > >>> getRootLogger().setLevel( level ); > >>> } > >>> > >>> } > >>> > >> > +------------------------------------------------------------------------------------------------------------------------------------+ > >>> > >>> and ConfigurationFactory: > >>> > >>> > >> > +------------------------------------------------------------------------------------------------------------------------------------+ > >>> class MyConfigurationFactory > >>> extends ConfigurationFactory > >>> { > >>> > >>> private final String levelName; > >>> > >>> private final String pattern; > >>> > >>> public MyConfigurationFactory( String levelName, String pattern ) > >>> { > >>> this.levelName = levelName; > >>> this.pattern = pattern; > >>> } > >>> > >>> @Override > >>> protected String[] getSupportedTypes() > >>> { > >>> return new String[] { "*" }; > >>> } > >>> > >>> @Override > >>> public Configuration getConfiguration( ConfigurationSource source ) > >>> { > >>> return new MyLoggingConfiguration( levelName, pattern ); > >>> } > >>> > >>> } > >>> > >> > +------------------------------------------------------------------------------------------------------------------------------------+ > >>> > >>> then, as specified in the Javadoc, invoke > >>> ConfigurationFactory#setConfigurationFactory(new > >>> MyConfigurationFactory("INFO", "[%level] %message%n")) before any > >>> other calls to Log4j, but when my application starts, an exception is > >>> thrown: > >>> > >>> > >> > +------------------------------------------------------------------------------------------------------------------------------------+ > >>> Exception in thread "main" java.lang.NullPointerException: No > >>> Configuration was provided > >>> at > >> > org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:323) > >>> at > >> > org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:370) > >>> at > >> > org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:149) > >>> at > >> > org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:85) > >>> at > >> > org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:34) > >>> at > >> org.apache.logging.log4j.LogManager.getLogger(LogManager.java:364) > >>> at > >> org.apache.logging.log4j.LogManager.getLogger(LogManager.java:319) > >>> ... > >>> > >> > +------------------------------------------------------------------------------------------------------------------------------------+ > >>> > >>> What am I doing wrong? > >>> Many thanks in advance, all the best! > >>> -Simo > >>> > >>> http://people.apache.org/~simonetripodi/ > >>> http://twitter.com/simonetripodi > >>> > >>> --------------------------------------------------------------------- > >>> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > >>> For additional commands, e-mail: log4j-user-h...@logging.apache.org > >>> > >> > >> > >> > >> -- > >> http://www.grobmeier.de > >> https://www.timeandbill.de > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > >> For additional commands, e-mail: log4j-user-h...@logging.apache.org > >> > >> > > > > > > -- > > E-Mail: garydgreg...@gmail.com | ggreg...@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-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > -- E-Mail: garydgreg...@gmail.com | ggreg...@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