say I have a multi-line text "a\nb\nc"; when I log it, eg with the "debug" method, I get only one log;
this is the expected behaviour but then the lines excluding the first are displayed too on the left in the output :
1234 [1] [DEBUG] Test - a
b
c
1235 [1] [DEBUG] Test - ...
A simple workaround is to generate one log per line to obtain :
1234 [1] [DEBUG] Test - a
1235 [1] [DEBUG] Test - b
1236 [1] [DEBUG] Test - c
1237 [1] [DEBUG] Test - ...
_
Is there any way of having this kind of handling automatically or should I write a simple wrapper to manage this setting ?
_
Thanks in advance.
Not possible and not recommended.
In your first example, it's clear that there exist two log statements, whereas in your second example one might assume at a glance that there are four of them.
One log statement should provide a single source information about what happened and when it happened, and that information should be useful in some way.
Imagine if you have one error statement, like an exception, that will span across 30 or so lines because of its stack trace. That would look like 30 errors in your case, and an automated tool might also report it as 30 errors. This is misinformation and should be avoided.
Not to mention "one log statement != one written log" might cause synchronization havoc when you're dealing with more complex logging situations, with multiple threads writing to the same file at the same time, or worse, multiple JVMs doing so.
If the "too far on the left" thing is giving you much grief, I'd suggest doing some post processing on generated log file, such as adding 8 spaces or so at the beginning of every line that doesn't contain [DEBUG], [INFO],...