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

Janardhan Naidu edited comment on LOG4J2-3388 at 2/16/22, 12:08 PM:
--------------------------------------------------------------------

HI, 

 

I am now migrating to log4j2.x, now facing one issue while implementing 
customer log levels, please help here.

 

*in java code:*

final Logger logger = LogManager.getLogger();

Level lev = Level.toLevel("ALWAYS"); 

logger.log(lev, " from custom level Always."); 

 

*in log4j2.properties:*

customLevels = ALWAYS

customLevel.ALWAYS.name = ALWAYS
customLevel.ALWAYS.intLevel = 525

 

I am not getting the logs printed, instead getting number format error,

 

Exception in thread "main" *java.lang.NumberFormatException: For input string: 
"ALWAYS"*
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at 
org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.build(PropertiesConfigurationBuilder.java:126)
    at 
org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:56)
    at 
org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:35)
    at 
org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:557)
    at 
org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:481)
    at 
org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:323)
    at 
org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:695)
    at 
org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:716)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:270)
    at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:245)
    at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:176)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:666)

Thanks

Janardhan 


was (Author: JIRAUSER284614):
HI, 

 

I am now migrating to log4j2.x, now facing one issue while implementing 
customer log levels, please help here.

 

*in java code:*

final Logger logger = LogManager.getLogger();

Level lev = Level.toLevel("ALWAYS"); 

logger.log(lev, " from custom level Always."); 

 

*in log4j2.properties:*

customLevels = ALWAYS

customLevel.ALWAYS.name = ALWAYS
customLevel.ALWAYS.value = 525

 

I am not getting the logs printed, instead getting number format error,

 

Exception in thread "main" *java.lang.NumberFormatException: For input string: 
"ALWAYS"*
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at 
org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.build(PropertiesConfigurationBuilder.java:126)
    at 
org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:56)
    at 
org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:35)
    at 
org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:557)
    at 
org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:481)
    at 
org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:323)
    at 
org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:695)
    at 
org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:716)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:270)
    at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:245)
    at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:176)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:666)

Thanks

Janardhan 

> Migration from log4j1.x to log4j2.x
> -----------------------------------
>
>                 Key: LOG4J2-3388
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3388
>             Project: Log4j 2
>          Issue Type: Question
>            Reporter: Janardhan Naidu
>            Priority: Major
>
> We are planning to upgrade log4j1.x to log4j2.x.
> So we went through the migration document: 
> [https://logging.apache.org/log4j/2.x/manual/migration.html] 
> in the above document, It says that (They must not access methods and classes 
> internal to the Log4j 1.x implementation such as Appenders, LoggerRepository 
> or Category’s callAppenders method.) 
> and In our product, currently we are using log4j1.x and we are extending some 
> of the log4j1.x classes like PatternParser, FileAppender etc... which were 
> made final in log4j2.x  so can we make use of Log4j 1.x bridge.?  If yes how 
> we can do that.
>  
> what could be the better option to migrate log4j 1.x to log4j 2.x as we are 
> making use of log4j internal classes? 
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to