-1

Is there any way to fix such behaviour?

Examples: example one

example two

In the log files everything is okay, but in the tool that shows the logfiles some lines are like this:

enter image description here

Edd
  • 3,724
  • 3
  • 26
  • 33
maxpovver
  • 1,580
  • 14
  • 25
  • 1
    Unfortunately, your question is quite unclear. Can you provide an example? What loggers? Where is the new line missing? Only in the console? In log files, too? If it's only in the console, I would guess that two (or more) objects are writing to the console (for example, you are doing `System.out.print(...)`additionally to the logging), which can mess up your output, of course. – Florian Schaetz Jul 23 '15 at 12:08
  • Can you post where your logger is defined? xml maybe? – Danielson Jul 23 '15 at 12:10
  • too hard to explain without showing companie's code which I can not do. Will go find help in some better place. – maxpovver Jul 23 '15 at 12:27
  • @maxpovver Feel free to post an answer if you do solve it. Without the full context of the problem any answer would be something of a guess. Providing the details requested by Florian would help narrow it down. – Edd Jul 23 '15 at 12:35
  • I'd guess the next question is "what tool are you using to view the logfiles?". If the log files themselves are fine, I don't think it's a log4j problem. – Edd Jul 23 '15 at 13:08
  • I got that already. but I can't delete this qiuestion now... @Edd – maxpovver Jul 23 '15 at 13:23

1 Answers1

2

Log4j is designed to write what you give to it... no println function.

So you must add it to your log message + "\n" or create a FileAppender that adds new line in each log entry.

Check this answer

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
  • 2
    I'm fairly certain that this is incorrect. The linked question does not appear to be about what you think it's about - that wanted additional, completely blank, lines to be inserted in the log file. You shouldn't have to append a newline character onto the end of your log messages, at least not with a standard-ish configuration. – Edd Jul 23 '15 at 12:28
  • "So you must add it to your log message + "\n" " seriously? the logger must care about it itself when we use .info() / .debug() functions. and usually it does, but fails sometimes without obvious reason – maxpovver Jul 23 '15 at 12:31
  • @Jordi Castilla is almost correct. To add a new line automatically after a log message your patternLayout pattern value needs to be something like `pattern="%m%n"`. The `%n` is what sets the new line, `\n` might also work but is not exactly the log4j2 config way. – alan7678 Jul 23 '15 at 15:11
  • to do a blank line between each message simply use `pattern="%m%n%n"` – alan7678 Jul 23 '15 at 15:12