DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26435>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26435 Changing logger priority via JMX Summary: Changing logger priority via JMX Product: Log4j Version: 1.2 Platform: Other OS/Version: Other Status: NEW Severity: Enhancement Priority: Other Component: Other AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] It's possible to change the log level of a logger by using the JMX interface class LoggerDynamicMBean class in LOG4J. The setAttribute() methods set a new priority but you cannot change the priority for an explicit category only for the root logger (see log4j.properties file) at the end of this description. Original source snippet of setAttribute(): if (name.equals("priority")) { if (value instanceof String) { String s = (String) value; Level p = logger.getLevel(); if (s.equalsIgnoreCase("NULL")) { p = null; } else { p = OptionConverter.toLevel(s, p); } logger.setPriority(p); } } else { throw (new AttributeNotFoundException("Attribute " + name + " not found in " + this.getClass().getName())); } The OptionConverter used in this codes also provides a mechanism to internally change a level for one Level by passing level and new value separated with a #- sign. But this only leads to a ClassNotFoundException (e.g. "INFO#tui.musyk" => no class) or InvocationTargetException. There seems no way to influence the behaviour of a single package or class logger via JMX, even though it would be very easy by adding an additional method to the Log4J interface classes. E.g. something like: public void setLogLevelForClassOrPackage( String className, String newLevelAsString) { // get the old logger responsible for this class or package Logger oldLogState = LogManager.getLogger(className); // get its current level Level oldLevel = oldLogState.getLevel(); Category cat = oldLogState.getParent(); while (oldLevel == null) { if (cat != null) { oldLevel = cat.getLevel(); cat = cat.getParent(); } else { break; } } // create a newLevel from the old level and the new level string // representation Level newLevel = OptionConverter.toLevel(newLevelAsString, oldLevel); // set the new level oldLogState.setLevel(newLevel); } ----------------- Current log4j.properties content: log4j.additivity.tui.musyk=false log4j.rootLogger=DEBUG,MUSYK1,MUSYK2 log4j.category.tui.musyk=DEBUG,MUSYK1,MUSYK2 log4j.category.test.musyk=DEBUG,MUSYK1,MUSYK2 log4j.category.tui.irisplus=DEBUG,MUSYK1,MUSYK2 log4j.appender.MUSYK1=org.apache.log4j.ConsoleAppender log4j.appender.MUSYK2=org.apache.log4j.RollingFileAppender log4j.appender.MUSYK2.File=D:/tmp/log/musyk.log log4j.appender.MUSYK2.Append=false log4j.appender.MUSYK2.MaxFileSize=8096KB log4j.appender.MUSYK2.MaxBackupIndex=1 log4j.appender.MUSYK1.layout=org.apache.log4j.PatternLayout log4j.appender.MUSYK2.layout=org.apache.log4j.PatternLayout log4j.appender.MUSYK1.layout.ConversionPattern=%-5p [%t] %-d{dd.MM. HH:mm:ss:SSS} %m \n log4j.appender.MUSYK2.layout.ConversionPattern=%m \n log4j.debug=true --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
