[ 
https://issues.apache.org/jira/browse/LOG4J2-3419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17502276#comment-17502276
 ] 

Ragini Gawande commented on LOG4J2-3419:
----------------------------------------

I did some debugging here and following is my finding

log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java

 
{noformat}
157 public static Level toLevel(String value, Level defaultValue) {
158 if (value == null) {
159 return defaultValue;
160 }
161
162 value = value.trim();
163
164 int hashIndex = value.indexOf('#');
165 if (hashIndex == -1) {
166 if ("NULL".equalsIgnoreCase(value)) {
167 return null;
168 }
169 // no class name specified : use standard Level class
170 return Level.toLevel(value, defaultValue);
171 }{noformat}
 

 

here its using Level.toLevel(value, defaultValue) of org.apache.log4j.Level 
instead of org.apache.logging.log4j.Level.toLevel

as we have defined new custom levels in 
org.apache.logging.log4j.Level.forName() its unable to return the correct level 
from org.apache.log4j.Level and instead of actual level it returns defaultValue 
which is DEBUG.

 

Can you please verify if the findings are correct? if yes then please suggest a 
way to define custom logging level for org.apache.log4j.Level

> 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
>            Assignee: Piotr Karwasz
>            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)

Reply via email to