3

I want to know if there's something already done, an ext library to do such thing?
I need the logger to be redirected to a StringBuffer for then ALL that text to be included in a database record as a message.
First of all, is that a good practice??
What I'm doing now is using a new Appender class and having that StringBuffer object, then retrieving and storing.

Thanks in advance!

Juan Diego
  • 863
  • 1
  • 10
  • 22
  • possible duplicate of [Custom logging to gather messages at runtime](http://stackoverflow.com/questions/1002926/custom-logging-to-gather-messages-at-runtime) – dogbane Jan 13 '11 at 18:16
  • What do you mean "ALL that text"? Do you mean the StringBuffer stores up results of multiple logging calls and then periodically its contents get written to a database? – Nathan Hughes Jan 13 '11 at 18:18
  • Yes Nathan, exactly that, althought not periodically but when the application's processing steps finish. – Juan Diego Jan 13 '11 at 18:32
  • Just checked @dogbane, it's that, but that buffer must be shared by all classes within the application. I'm finding for a proper solution, avoiding to share a static field across it. What that link says is what I'm using. – Juan Diego Jan 13 '11 at 18:32

2 Answers2

0

I had exactly the same issue and wrote my own at some point https://github.com/artgo/stringbuffer-logger

Artem
  • 7,275
  • 15
  • 57
  • 97
0

A custom log4j appender is the way to go in your case and it's transparent for SLF4J.

dSebastien
  • 1,983
  • 2
  • 21
  • 31