Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1314

NumberFormatException: For input string: "-"

    XMLWordPrintable

Details

    Description

      I need to print the class, method and line number in the logger. FOr that I am using the following entry:

       

      <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>
      

       

      As you can see, my pattern is 

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

       

      Then I am getting the following error:

       

      09:31:44,119 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@29: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)
      

       

      But if I use 

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

      Then there is no error.

       

      Can someone please take a look. Here is my pom entry:

      <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>
      

       

      Attachments

        Activity

          People

            logback-dev Logback dev list
            SankhaGhosh Sankha Subhra Ghosh
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: