[ https://issues.apache.org/jira/browse/LOG4J2-3419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17499999#comment-17499999 ]
Ragini Gawande edited comment on LOG4J2-3419 at 3/2/22, 9:14 AM: ----------------------------------------------------------------- I have modified my constructor as suggested and it is giving me expected results in terms of printing the Level name correctly But I am still facing an issue while setting that custom log level in my log4j.properties file public static final int SEVERE_INT = 320; public static final Level SEVERE = new Level(SEVERE_INT, "SEVERE", 2); Now if I use SEVERE in properties file it consider it to be DEBUG by default Following is my log4j,properties file {noformat} CustomLevels=SEVERE CustomLevel.SEVERE.name=SEVERE CustomLevel.SEVERE.intLevel=320 #customLevel.SEVERE=320 log4j.rootLogger=SEVERE, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender #log4j.appender.stdout.Threshold=SEVERE log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d Main[%pid] :%t: %c %-4p - %m%n{noformat} I tried setting CustomLevels properties but still not getting expected result Expected output {noformat} 2022-03-02 14:22:49,982 Main[11728] :main: example.com.Test FATAL - Level.FATAL log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test ERROR - Level.ERROR log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test WARNING - Level.WARNING log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test SEVERE - Level.SEVERE log{noformat} Actual output: {noformat} 2022-03-02 14:22:49,982 Main[11728] :main: example.com.Test FATAL - Level.FATAL log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test ERROR - Level.ERROR log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test WARNING - Level.WARNING log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test SEVERE - Level.SEVERE log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test INFO - Level.INFO log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test CONFIG - Level.CONFIG log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test FINE - Level.FINE log 2022-03-02 14:22:49,987 Main[11728] :main: example.com.Test FINER - Level.FINER log 2022-03-02 14:22:49,987 Main[11728] :main: example.com.Test FINEST - Level.FINEST log 2022-03-02 14:22:49,987 Main[11728] :main: example.com.Test DEBUG - Level.DEBUG log{noformat} Is there anything am missing or configuring incorrectly? was (Author: JIRAUSER285931): I have modified my constructor as suggested and it is giving me expected results in terms of printing the Level name correctly But I am still facing an issue while setting that custom log level in my log4j.properties file public static final int SEVERE_INT = 320; public static final Level SEVERE = new Level(SEVERE_INT, "SEVERE", 2); Now if I use SEVERE in properties file it consider it to be DEBUG by default Following is my log4j,properties file {noformat} CustomLevels=SEVERE CustomLevel.SEVERE.name=SEVERE CustomLevel.SEVERE.intLevel=320 #customLevel.SEVERE=320 log4j.rootLogger=SEVERE, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender #log4j.appender.stdout.Threshold=SEVERE log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d Main[%pid] :%t: %c %-4p - %m%n{noformat} I tried setting CustomLevels properties but still not getting expected result Expected output {noformat} 2022-03-02 14:22:49,982 Main[11728] :main: example.com.Test FATAL - Level.FATAL log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test ERROR - Level.ERROR log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test WARNING - Level.WARNING log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test SEVERE - Level.SEVERE log{noformat} Actual output: {noformat} 2022-03-02 14:22:49,982 Main[11728] :main: example.com.Test FATAL - Level.FATAL log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test ERROR - Level.ERROR log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test WARNING - Level.WARNING log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test SEVERE - Level.SEVERE log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test INFO - Level.INFO log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test CONFIG - Level.CONFIG log 2022-03-02 14:22:49,986 Main[11728] :main: example.com.Test FINE - Level.FINE log 2022-03-02 14:22:49,987 Main[11728] :main: example.com.Test FINER - Level.FINER log 2022-03-02 14:22:49,987 Main[11728] :main: example.com.Test FINEST - Level.FINEST log 2022-03-02 14:22:49,987 Main[11728] :main: example.com.Test DEBUG - Level.DEBUG log{noformat} Is there anything am missing or configuring incorrectly? > Unable to create custom logging level using log4j 2 Bridge API > -------------------------------------------------------------- > > Key: LOG4J2-3419 > URL: https://issues.apache.org/jira/browse/LOG4J2-3419 > Project: Log4j 2 > Issue Type: Bug > Components: Log4j 1.2 bridge > Affects Versions: 2.17.1 > Environment: Using log4j 2 bridge API: log4j-1.2-api-2.17.1.jar > Reporter: Ragini Gawande > Priority: Blocker > > Unable to create custom logging level using log4j 2 Bridge API > Following did not create a custom logging level > *public static final int FINE_INT = 13000;* > *public static final Level FINE = new Level(FINE_INT, "FINE", 7);* > > Using FINE logging level is considered to be DEBUG level by default while > printing it > *Adding log:* > log.log({*}Level.FINE{*},"PRINT: Level.FINE log"); > > *Expected log printed:* > 2022-02-25 15:50:09,208 Main[6788] :main: example.com.Test *FINE* - PRINT: > Level.FINE log > > *Actual log printed:* > 2022-02-25 15:50:09,208 Main[6788] :main: example.com.Test *DEBUG* - PRINT: > Level.FINE log -- This message was sent by Atlassian Jira (v8.20.1#820001)