LoggerConfig.getLoggers() returns a list of all the Loggers created by calls to LogManager.getLogger(), not a list of LoggerConfigs.
I don’t see a root logger being created in your code. I believe that means a default root logger will be used that logs at ERROR. From the code below it isn’t clear to me what the names are of the LoggerConfig objects you are creating. If none of them “match” the name of the current class then the behavior you are seeing would be expected. Also, you probably want to specify LogManager.getContext(false). Ralph > On Aug 10, 2015, at 11:08 AM, Xen <[email protected]> wrote: > > Hi again. > > So. I managed to get a new ConfigurationFactory running (just so as to avoid > the ERROR level message given by the StatusLogger when no config file is > found) that returns a DefaultConfiguration() for now. > > I happened to have overriden the wrong method. > "getConfiguration(ConfigurationSource)" is not directly called and when > configLocation is null, it will never be called. So I overrode > getConfiguration(String, URI) instead, and then it worked. > > So now I'm trying to -- outside of any Configuration class or subclass -- to > get a modest change to the configuration going. I am just trying to add Two > Loggers with associeted LoggerConfig, that will inherit the Appender from the > RootLogger. > > However, I am failing and I don't know why. > > ConfigurationFactory.setConfigurationFactory(new DefaultNoErrorFactory()); > LoggerContext lc = (LoggerContext)LogManager.getContext(); > Configuration conf = lc.getConfiguration(); > addLogger(conf, thunderbolt.Server.class, Level.TRACE, true); > addLogger(conf, telnet.Negotiator.class, Level.DEBUG, true); > lc.updateLoggers(); > > > My "addLogger" method simply does either one of two things: > > 1. call configuration.addLogger("name", new LoggerConfig("name", level, > additive)); > 2. call configuration.addLogger("name", LoggerConfig.createLogger("" + > additive, level, c.getName(), "false", > new org.apache.logging.log4j.core.config.AppenderRef[0], null, > conf, null)); > > When I do a print of configuration.getLoggers(), it prints the Map with the > contents of the two loggers (LoggerConfigs) I have added. > > However loggerContext.getLoggers() produces an empty Collection. > > Meanwhile, > > LogManager.getLogger() <-- which references the current class > -->.error("text") .. will produce output, but .info("text") will not, which > means it is not configured. > > Or rather, it just takes the value of the rootlogger (its level). > > I do not know how to get the loggers into the LoggerContext. What am I doing > wrong? The way it is explained, I do not need to add any appender (for now) > as it should inherit from the rootlogger. > > The page at https://logging.apache.org/log4j/2.x/manual/customconfig.html > shows almost the exact same code, except that it adds an Appender to the > Configuration and to the LoggerConfig. There are no errors and when I put the > StatusLogger to TRACE, It doesn't show anything meaningful: > > Output below. > > I don't really know what to do? > > Regards, Bart. > > > DEBUG StatusLogger Not in a ServletContext environment, thus not loading > WebLookup plugin. > DEBUG StatusLogger Not in a ServletContext environment, thus not loading > WebLookup plugin. > DEBUG StatusLogger Using ShutdownCallbackRegistry class > org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry > WARN StatusLogger Multiple logging implementations found: > Factory: org.apache.logging.log4j.core.impl.Log4jContextFactory, Weighting: 10 > Using factory: org.apache.logging.log4j.core.impl.Log4jContextFactory > DEBUG StatusLogger Not in a ServletContext environment, thus not loading > WebLookup plugin. > DEBUG StatusLogger Not in a ServletContext environment, thus not loading > WebLookup plugin. > DEBUG StatusLogger Took 0,149366 seconds to load 138 plugins from > sun.misc.Launcher$AppClassLoader@60e53b93 > DEBUG StatusLogger PluginManager 'Converter' found 33 plugins > WARN StatusLogger Unable to instantiate > org.fusesource.jansi.WindowsAnsiOutputStream > DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT > DEBUG StatusLogger Starting LoggerContext[name=Default, > org.apache.logging.log4j.core.LoggerContext@71c7db30]... > DEBUG StatusLogger Reconfiguration started for context[name=Default] at null > (org.apache.logging.log4j.core.LoggerContext@71c7db30) with optional > ClassLoader: null > DEBUG StatusLogger PluginManager 'ConfigurationFactory' found 3 plugins > DEBUG StatusLogger Not in a ServletContext environment, thus not loading > WebLookup plugin. > DEBUG StatusLogger Not in a ServletContext environment, thus not loading > WebLookup plugin. > DEBUG StatusLogger Not in a ServletContext environment, thus not loading > WebLookup plugin. > DEBUG StatusLogger Using configurationFactory > thunderbolt.log.DefaultNoErrorFactory@43a25848 > DEBUG StatusLogger Not in a ServletContext environment, thus not loading > WebLookup plugin. > DEBUG StatusLogger PluginManager 'Converter' found 33 plugins > WARN StatusLogger Unable to instantiate > org.fusesource.jansi.WindowsAnsiOutputStream > DEBUG StatusLogger Starting configuration > org.apache.logging.log4j.core.config.DefaultConfiguration@6a5fc7f7 > DEBUG StatusLogger PluginManager 'Core' found 69 plugins > DEBUG StatusLogger PluginManager 'Level' found 0 plugins > DEBUG StatusLogger Started configuration > org.apache.logging.log4j.core.config.DefaultConfiguration@6a5fc7f7 OK. > TRACE StatusLogger Stopping > org.apache.logging.log4j.core.config.DefaultConfiguration@1e643faf... > TRACE StatusLogger AbstractConfiguration stopped 0 AsyncLoggerConfigs. > TRACE StatusLogger AbstractConfiguration stopped 0 AsyncAppenders. > TRACE StatusLogger AbstractConfiguration stopped 1 Appenders. > TRACE StatusLogger AbstractConfiguration stopped 0 Loggers. > DEBUG StatusLogger Stopped > org.apache.logging.log4j.core.config.DefaultConfiguration@1e643faf OK > DEBUG StatusLogger Reconfiguration complete for context[name=Default] at null > (org.apache.logging.log4j.core.LoggerContext@71c7db30) with optional > ClassLoader: null > DEBUG StatusLogger Shutdown hook enabled. Registering a new one. > DEBUG StatusLogger LoggerContext[name=Default, > org.apache.logging.log4j.core.LoggerContext@71c7db30] started OK. > DEBUG StatusLogger Not in a ServletContext environment, thus not loading > WebLookup plugin. > DEBUG StatusLogger PluginManager 'Converter' found 33 plugins > WARN StatusLogger Unable to instantiate > org.fusesource.jansi.WindowsAnsiOutputStream > DEBUG StatusLogger Starting LoggerContext[name=1625635731, > org.apache.logging.log4j.core.LoggerContext@13a57a3b]... > DEBUG StatusLogger Reconfiguration started for context[name=1625635731] at > null (org.apache.logging.log4j.core.LoggerContext@13a57a3b) with optional > ClassLoader: null > DEBUG StatusLogger Using configurationFactory > thunderbolt.log.DefaultNoErrorFactory@43a25848 > DEBUG StatusLogger Not in a ServletContext environment, thus not loading > WebLookup plugin. > DEBUG StatusLogger PluginManager 'Converter' found 33 plugins > WARN StatusLogger Unable to instantiate > org.fusesource.jansi.WindowsAnsiOutputStream > DEBUG StatusLogger Starting configuration > org.apache.logging.log4j.core.config.DefaultConfiguration@7ca48474 > DEBUG StatusLogger PluginManager 'Core' found 69 plugins > DEBUG StatusLogger PluginManager 'Level' found 0 plugins > DEBUG StatusLogger Started configuration > org.apache.logging.log4j.core.config.DefaultConfiguration@7ca48474 OK. > TRACE StatusLogger Stopping > org.apache.logging.log4j.core.config.DefaultConfiguration@59e84876... > TRACE StatusLogger AbstractConfiguration stopped 0 AsyncLoggerConfigs. > TRACE StatusLogger AbstractConfiguration stopped 0 AsyncAppenders. > TRACE StatusLogger AbstractConfiguration stopped 1 Appenders. > TRACE StatusLogger AbstractConfiguration stopped 0 Loggers. > DEBUG StatusLogger Stopped > org.apache.logging.log4j.core.config.DefaultConfiguration@59e84876 OK > Current loggers: -------- > {telnet.Negotiator=telnet.Negotiator, thunderbolt.Server=thunderbolt.Server} > <== the Map from Configuration > ------------------------- > [] <== the Collection from LoggerContext > ------------------------- --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
