2017-06-14 108 views
0

我需要在記錄器中打印類,方法和行號。對於我使用下面的條目:NumberFormatException:對於輸入字符串:「 - 」logback

<appender name="ErrorFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> 
    <file>${log.dir}error.log</file> 
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
     <!-- daily rollover --> 
     <fileNamePattern>${log.dir}error.%d{yyyy-MM-dd}.%i.log</fileNamePattern> 
     <maxHistory>3</maxHistory> 
     <!--<totalSizeCap>10MB</totalSizeCap>--> 
     <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> 
      <MaxFileSize>10MB</MaxFileSize> 
     </TimeBasedFileNamingAndTriggeringPolicy> 
    </rollingPolicy> 
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> 
     <Pattern> 
      %d %-5p [%X{sessionId}] [%X{userId}] %C{1}.%-M:%L] %m%n 
     </Pattern> 
    </encoder> 
    <!--<encoder> 
     <pattern>%d %-5p [%X{sessionId}] [%X{userId}] %C{1}.%-M:%L] %m%n</pattern> 
    </encoder>--> 
</appender> 
<root level="ERROR"> 
    <appender-ref ref="ErrorFileAppender" /> 
</root> 

正如你看到的,我的模式是

%d %-5p [%X{sessionId}] [%X{userId}] %C{1}.%-M:%L] %m%n 

然後我收到以下錯誤:

09:31:44,119 |-ERROR in [email protected]:19 - RuntimeException in Action for tag [encoder] java.lang.NumberFormatException: For input string: "-" 
at java.lang.NumberFormatException: For input string: "-" 
at at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) 
at at java.lang.Integer.parseInt(Integer.java:572) 
at at java.lang.Integer.parseInt(Integer.java:615) 
at at ch.qos.logback.core.pattern.FormatInfo.valueOf(FormatInfo.java:73) 
at at ch.qos.logback.core.pattern.parser.Parser.T(Parser.java:136) 
at at ch.qos.logback.core.pattern.parser.Parser.E(Parser.java:96) 
at at ch.qos.logback.core.pattern.parser.Parser.Eopt(Parser.java:115) 
at at ch.qos.logback.core.pattern.parser.Parser.E(Parser.java:100) 
at at ch.qos.logback.core.pattern.parser.Parser.Eopt(Parser.java:115) 
at at ch.qos.logback.core.pattern.parser.Parser.E(Parser.java:100) 
at at ch.qos.logback.core.pattern.parser.Parser.Eopt(Parser.java:115) 
at at ch.qos.logback.core.pattern.parser.Parser.E(Parser.java:100) 
at at ch.qos.logback.core.pattern.parser.Parser.Eopt(Parser.java:115) 
at at ch.qos.logback.core.pattern.parser.Parser.E(Parser.java:100) 
at at ch.qos.logback.core.pattern.parser.Parser.Eopt(Parser.java:115) 
at at ch.qos.logback.core.pattern.parser.Parser.E(Parser.java:100) 
at at ch.qos.logback.core.pattern.parser.Parser.Eopt(Parser.java:115) 
at at ch.qos.logback.core.pattern.parser.Parser.E(Parser.java:100) 
at at ch.qos.logback.core.pattern.parser.Parser.Eopt(Parser.java:115) 
at at ch.qos.logback.core.pattern.parser.Parser.E(Parser.java:100) 
at at ch.qos.logback.core.pattern.parser.Parser.Eopt(Parser.java:115) 
at at ch.qos.logback.core.pattern.parser.Parser.E(Parser.java:100) 
at at ch.qos.logback.core.pattern.parser.Parser.parse(Parser.java:91) 
at at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:83) 
at at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:28) 
at at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.end(NestedComplexPropertyIA.java:161) 
at at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309) 
at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193) 
at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179) 
at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62) 
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165) 
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152) 
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110) 
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53) 
at at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75) 
at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150) 
at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84) 
at at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55) 
at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150) 
at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124) 
at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412) 
at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357) 
at at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155) 
at at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132) 
at at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273) 
at at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:164) 
at at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:228) 
at at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:89) 
at at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:58) 
at at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:61) 
at at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:136) 
at at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 

但是,如果使用

%d %-5p [%X{sessionId}] [%X{userId}] %m%n 

那麼沒有錯誤要麼。

有人可以請看看。這是我的POM條目:

<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>jcl-over-slf4j</artifactId> 
    <version>1.7.25</version> 
</dependency> 
<dependency> 
    <groupId>org.logback-extensions</groupId> 
    <artifactId>logback-ext-spring</artifactId> 
    <version>0.1.4</version> 
</dependency> 
<dependency> 
    <groupId>ch.qos.logback</groupId> 
    <artifactId>logback-classic</artifactId> 
    <version>1.2.3</version> 
    <scope>test</scope> 
</dependency> 

回答

0

更改%-M%M

所以你的模式就變成了:

<Pattern> 
    %d %-5p [%X{sessionId}] [%X{userId}] %C{1}.%M:%L] %m%n 
</Pattern> 
+0

嗨@roby,我已嘗試了。徒勞無功。:( – Sankha

相關問題