1

Do any one knows how to add a empty line in slf4j logs without its formatting. To get empty log I have added empty string as log.

log.error("");

I need to get it with out formatting, Just empty line, Please help.

Rockstar
  • 2,228
  • 3
  • 20
  • 39
Prabhath
  • 585
  • 6
  • 20

2 Answers2

3

In your logback.xml, declare a "minimal" appender that doesn't embellish the log message with timestamps or log levels or anything like so:

<appender name="minimal" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%m%n</pattern>
    </encoder>
</appender>

Then declare a logger that uses that appender like so:

<logger name="blank.line.logger" level="ALL" additivity="false">
    <appender-ref ref="minimal"/>
</logger>

In your Java code where you'd like to produce empty log lines, you'll need a reference to that logger separate from whatever other logger you're using for regular log messages, something like

private static final Logger blankLineLogger = LoggerFactory.getLogger("blank.line.logger");

Then you can get your desired blank line in the log output with

blankLineLogger.info("");
palimpsestor
  • 1,038
  • 1
  • 8
  • 28
0

The accepted answser is a bit tricky, for me I just use a simple log.error("\n") , or append a \n in the previous log line.

Leon
  • 3,124
  • 31
  • 36