[ https://issues.apache.org/jira/browse/LOG4J2-3431 ]
Tukesh deleted comment on LOG4J2-3431: -------------------------------- was (Author: JIRAUSER282001): In OptionConverter.java replacing convertLevel(final Level level) with following implementation solves problems of custom levels. public static org.apache.logging.log4j.Level convertLevel(final Level level) { return org.apache.logging.log4j.Level.forName(level.toString(),level.toInt()); } Do you agree with this change ? > log4j bridge API :- Log message filtering based on UtilLoggingLevel fails and > all messages are written into log files > --------------------------------------------------------------------------------------------------------------------- > > Key: LOG4J2-3431 > URL: https://issues.apache.org/jira/browse/LOG4J2-3431 > Project: Log4j 2 > Issue Type: Bug > Environment: JDK 1.8 > > -Dlog4j1.compatibility=true > # log4j-1.2-api-2.17.2.jar > # log4j-api-2.17.2.jar > # log4j-core-2.17.2.jar > > > Reporter: Tukesh > Assignee: Piotr Karwasz > Priority: Major > > log4j bridge API :- Log message filtering based on UtilLoggingLevel fails and > all messages are written into log files > > {code:java} > // demo code > package test.logger;import org.apache.log4j.Logger; > import org.apache.log4j.helpers.UtilLoggingLevel;import java.io.*; > import java.sql.SQLException; > import java.util.concurrent.TimeUnit; > public class LoggerExample{ > static Logger log = Logger.getLogger(LoggerExample.class.getName()); > > public static void main(String[] args)throws IOException,SQLException{ > System.out.println("I'm running..."); > while(true){ > System.out.println("I'm running..."); > > log.info("Log4j-shell this is a info message"); > > log.log(UtilLoggingLevel.INFO,"INFO"); > log.log(UtilLoggingLevel.FINE,"FINE"); > log.log(UtilLoggingLevel.FINER,"FINER"); > log.log(UtilLoggingLevel.FINEST,"FINEST"); > log.log(UtilLoggingLevel.CONFIG,"CONIG"); > > try { > TimeUnit.MILLISECONDS.sleep(1000); > } catch (InterruptedException e) { > e.printStackTrace(); > } > } > } > } {code} > {code:java} > log4j.rootLogger=FINE#org.apache.log4j.helpers.UtilLoggingLevel,DMCC_TRACE_LOGGER > > log4j.appender.DMCC_TRACE_LOGGER.Threshold=FINE#org.apache.log4j.helpers.UtilLoggingLevel > log4j.appender.DMCC_TRACE_LOGGER=org.apache.log4j.RollingFileAppender > log4j.appender.DMCC_TRACE_LOGGER.File=Dmcc-trace.log > log4j.appender.DMCC_TRACE_LOGGER.Append=true > log4j.appender.DMCC_TRACE_LOGGER.layout=org.apache.log4j.PatternLayout > log4j.appender.DMCC_TRACE_LOGGER.layout.ConversionPattern=%d > DmccMain[%X{PID}] :%t: %c %-4p - %m%n > log4j.appender.DMCC_TRACE_LOGGER.maxFileSize=10MB > log4j.appender.DMCC_TRACE_LOGGER.maxBackupIndex=20 > {code} > > > +*Investigation :-*+ > convertLevel function from OptionConverter.java doesn't consider > UtilLoggingLevel level for mapping. so it sets Level as DEBUG for > UtilLoggingLevel classes. > {code:java} > // code placeholder > final org.apache.logging.log4j.Level level = levelStr == null ? > org.apache.logging.log4j.Level.ERROR : > OptionConverter.convertLevel(levelStr, org.apache.logging.log4j.Level.DEBUG); > loggerConfig.setLevel(level); > LOGGER.debug("Logger {} level set to {}", loggerName, level); > > > OptionConverter.java :- > public static org.apache.logging.log4j.Level convertLevel(final Level > level) { > if (level == null) { > return org.apache.logging.log4j.Level.ERROR; > } > if (level.isGreaterOrEqual(Level.FATAL)) { > return org.apache.logging.log4j.Level.FATAL; > } else if (level.isGreaterOrEqual(Level.ERROR)) { > return org.apache.logging.log4j.Level.ERROR; > } else if (level.isGreaterOrEqual(Level.WARN)) { > return org.apache.logging.log4j.Level.WARN; > } else if (level.isGreaterOrEqual(Level.INFO)) { > return org.apache.logging.log4j.Level.INFO; > } else if (level.isGreaterOrEqual(Level.DEBUG)) { > return org.apache.logging.log4j.Level.DEBUG; > } else if (level.isGreaterOrEqual(Level.TRACE)) { > return org.apache.logging.log4j.Level.TRACE; > } > return org.apache.logging.log4j.Level.ALL; > } > {code} -- This message was sent by Atlassian Jira (v8.20.1#820001)