user3568504
user3568504

Reputation: 31

Log4j working fine on localhost, but in jenkins, all log statements printed on same line

After executing the test cases, all the log steps will be written into a file. Like as shown below.

[INFO ][2014-04-16 16:49:02,945] - Reading data properties from dataSource file

[INFO ][2014-04-16 16:49:02,945] - DataSource.properties file path

[INFO ][2014-04-21 08:08:27,134] - Reading data properties from dataSource file [INFO ][2014-04-21 08:08:27,135] - DataSource.properties file path

In Jenkins, after completing the first log statement, second statement will be added to it. But my requirement is first statement in first line, second statement in second line. So how can I specify the next line character in Log4j?

Upvotes: 2

Views: 1203

Answers (1)

xav
xav

Reputation: 5628

In Log4j (v1 or v2), you can use %n in your PatternLayout to insert the new line character. You can read more about Log4j patterns here:

Here are Log4j configurations examples:

  • Log4j v1: log4j.appender.FileAppender.layout.ConversionPattern=%-5p [%t] %m%n
  • Log4j v2: <PatternLayout pattern="%-5p [%t] %m%n"/>

Upvotes: 1

Related Questions