If I understand your question correctly, the Configuration interface has a getLoggers() call that returns a Map of all the LoggerConfig objects.
Ralph On Jul 26, 2013, at 6:51 AM, SMITH, CURTIS wrote: > Oh! So you're right. That's what feed back is for. <logger > name="abc" I see the name I need to use now. > > My 2nd part of this question is, why should I embed into code a > configuration dependency of " abc" , there needs to be a get list/iterator of > loggers API to prevent having ot keep code and log4j2.xml in sync, right? > > Tnx curt > > -----Original Message----- > From: Ralph Goers [mailto:[email protected]] > Sent: Thursday, July 25, 2013 6:39 PM > To: Log4J Users List > Subject: Re: programmatically setting level for many loggers not working for > 2nd - Nth logger > > I don't understand. You don't have any loggers configured named "VIDEO", > "DLA" or "DEVICES". You do have appenders with those names. All those > getLoggerConfig calls should end up returning the root loggerConfig. > > Ralph > > > On Jul 25, 2013, at 2:36 PM, SMITH, CURTIS wrote: > >> Programmatical setting of loggers only works for the first logger declared >> unfortunately. Further there's a missing API that allows me to get a list >> of loggers (or configurations) to walk and set level like get Category in >> v1. See my code below that has coupling between code and log4j2.xml >> >> Only the DLA logger seems to work for setting level at run time. If I >> remove the level="DEBUG" attributes from the loggers, then I don't get any >> logs. >> >> Code: >> if (logLevelDebug != null) { >> LoggerContext ctx = (LoggerContext) >> LogManager.getContext(false); >> Configuration config = ctx.getConfiguration(); >> LoggerConfig loggerConfig = >> config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); >> loggerConfig.setLevel(Level.DEBUG); >> loggerConfig = config.getLoggerConfig("VIDEO"); // doesn't >> work. Is coupling with log4j2.xml >> loggerConfig.setLevel(Level.DEBUG); >> loggerConfig = config.getLoggerConfig("DLA"); // this >> works, but is first declared in log4j2.xml >> loggerConfig.setLevel(Level.DEBUG); >> loggerConfig = config.getLoggerConfig("DEVICES");// doesn't >> work >> loggerConfig.setLevel(Level.DEBUG); >> ctx.updateLoggers(); // This causes all Loggers to refetch >> information from their LoggerConfig. >> >> logger.debug("ErrorLogsUI: setting root logger to DEBUG"); >> } >> String logLevelWarn = req.getParameter("logLevelWarn"); >> >> if (logLevelWarn != null) { >> LoggerContext ctx = (LoggerContext) >> LogManager.getContext(false); >> Configuration config = ctx.getConfiguration(); >> LoggerConfig loggerConfig = >> config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); >> loggerConfig.setLevel(Level.WARN); >> loggerConfig = config.getLoggerConfig("VIDEO"); >> loggerConfig.setLevel(Level.WARN); >> loggerConfig = config.getLoggerConfig("DLA"); >> loggerConfig.setLevel(Level.WARN); >> loggerConfig = config.getLoggerConfig("DEVICES"); >> loggerConfig.setLevel(Level.WARN); >> ctx.updateLoggers(); // This causes all Loggers to refetch >> information from their LoggerConfig. >> >> logger.warn("ErrorLogsUI: setting root logger to WARN"); >> } >> >> <?xml version="1.0" encoding="UTF-8"?> >> <configuration status="trace" level="trace" > >> <appenders> >> <FastRollingFile name="DLA" >> fileName="/tmp/att/sync/log/dla.log" >> filePattern="/tmp/att/sync/log/dla.log.%i" >> append="true"> >> <PatternLayout> >> >> <pattern>[%d][%-5p][%-15t][%-15c{1}]:%m%n</pattern> >> </PatternLayout> >> <Policies> >> <SizeBasedTriggeringPolicy size="3 MB" /> >> </Policies> >> <DefaultRolloverStrategy max="2" /> >> </FastRollingFile> >> <FastRollingFile name="DEVICES" >> fileName="/tmp/att/sync/log/dla_devices.log" >> filePattern="/tmp/att/sync/log/dla_devices.log.%i" >> append="true"> >> <PatternLayout> >> >> <pattern>[%d][%-5p][%-15t][%-15c{1}]:%m%n</pattern> >> </PatternLayout> >> <Policies> >> <SizeBasedTriggeringPolicy size="3 MB" /> >> </Policies> >> <DefaultRolloverStrategy max="1" /> >> </FastRollingFile> >> <FastRollingFile name="VIDEO" >> fileName="/tmp/att/sync/log/dla_video.log" >> filePattern="/tmp/att/sync/log/dla_video.log.%i" >> append="true"> >> <PatternLayout> >> >> <pattern>[%d][%-5p][%-15t][%-15c{1}]:%m%n</pattern> >> </PatternLayout> >> <Policies> >> <SizeBasedTriggeringPolicy size="3 MB" /> >> </Policies> >> <DefaultRolloverStrategy max="1" /> >> </FastRollingFile> >> <Console name="CO" target="SYSTEM_OUT"> >> <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - >> %m%n" /> >> </Console> >> </appenders> >> <loggers> >> <logger name="com.att.dlc.afm" additivity="false" > >> <appender-ref ref="DLA" /> >> </logger> >> <logger name="com.att.dlc.devices" additivity="false" >> level="debug"> >> <appender-ref ref="DEVICES" /> >> </logger> >> <logger name="com.att.dlc.util.serialport" additivity="false" >> level="debug"> >> <appender-ref ref="DEVICES" /> >> </logger> >> <logger name="com.att.dlc.webcamserver" additivity="false" >> level="debug"> >> <appender-ref ref="VIDEO" /> >> </logger> >> <logger name="com.att.dlc.devices.cameras" additivity="false" >> level="debug"> >> <appender-ref ref="VIDEO" /> >> </logger> >> <root level="debug"> >> <appender-ref ref="DLA" /> >> </root> >> </loggers> >> </configuration> >> >> Curt Smith >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
