0

Pretty new to all this so excuse any beginner mistakes.

I was wondering if I was able to get log4j to write multiple messages to the same db record in a single log write. example

log.debug("Message 1" , "Message 2"); or log.debug("Message 1" , 7);

Can log4j only take a single message for writing?

Thanks

Magezy
  • 109
  • 3
  • 8

1 Answers1

2

There exists a predefined appender for it (org.apache.log4j.jdbc.JDBCAppender), but it has limits, check the API.

As for the second part of your question, each call to Logger.debug/info/warn, etc., causes a LoggingEvent object to be created in log4j internals, which is a "unit of logging". Log4j does not append anything to this object later, just logs it and forgets it.

If you need to merge a complicated text and log it as one, you should use this technique, or better use log4j with slf4j, which can construct log strings with {} placeholders, sort of like C function printf.

Community
  • 1
  • 1
MaDa
  • 10,511
  • 9
  • 46
  • 84