Why is there a space at the beginning of each line in my logbook created by Logback?

I am using Logback for logging. There is a space at the beginning of each line after the first line. Any idea why?

Below is my logback.xml:

<?xml version="1.0" encoding="utf-8"?> <configuration debug="true"> <property name="log.pattern" value="%d{yyyy/MM/dd HH:mm:ss.SSS} %-5level [%logger{0}] %msg%n %ex"/> <property name="log.file.prefix" value="${app.home}/var/log/${app.name}"/> <appender name="DEFAULT" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${log.file.prefix}.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${log.file.prefix}.%d{yyyyMMdd}.%i.log.zip</fileNamePattern> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>500MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <Pattern>${log.pattern}</Pattern> </encoder> </appender> <!-- info for everything else --> <root level="info"> <appender-ref ref="DEFAULT"/> </root> </configuration> 

As a result, the log output is as follows (note that the first line has no space):

 2012/02/06 13:34:09.875 INFO [BrokerService] Using Persistence Adapter: MemoryPersistenceAdapter 2012/02/06 13:34:09.875 INFO [BrokerService] ActiveMQ 5.3.1 JMS Message Broker (localhost) is starting 2012/02/06 13:34:09.875 INFO [BrokerService] For help or more information please see: http://activemq.apache.org/ 2012/02/06 13:34:09.953 INFO [ManagementContext] JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi 2012/02/06 13:34:10.328 INFO [BrokerService] ActiveMQ JMS Message Broker (localhost, ID:NZucker-NYL-3937-1328553250062-0:0) started 2012/02/06 13:34:10.343 INFO [TransportConnector] Connector vm://localhost Started 
+4
source share
3 answers

In fact, I think this is the space after the newline (% n) and before the exception (% ex). Since there are no exceptions in any of the results you show, and you are not adding a new line after the exception, it prints your information, a new line, a space, an empty line, and then your information again.

I wonder if logback automatically adds a new line after the output of% ex, if it is not equal to the empty line.

+6
source

Change the value of log.pattern to

  "%d{yyyy/MM/dd HH:mm:ss.SSS} %-5level [%logger{0}] %msg%n%ex" 

Note: there is no space between% n and% ex.

+7
source

You have %n in your log.pattern, which gives you a new line. Try:

 <property name="log.pattern" value="%d{yyyy/MM/dd HH:mm:ss.SSS} %-5level [%logger{0}] %msg %ex"/> 

Template layout information: http://logback.qos.ch/manual/layouts.html

+1
source

Source: https://habr.com/ru/post/1395073/


All Articles