I'm looking into the idea of creating a new logger to hold log statements internally until an error occurs.
So in the system I'm working on, it is a sequence process (no parallel work, with a set start point and end point). I'd like to have my info() lines buffered in memory & at the end if an error occurs, flush them out, or if its a success then don't bother logging them.
I'm not too worried about memory use, its only 15 lines at a time (across several classes). But since it can process 100's of items a second(each creating 15 lines), the logging can become verbose with data that isn't that needed.
The other option it to log to one main file, which can be tailed. Then if an error occurs, flush the last buffer to an ERROR log.
Does anyone know of a SLF4J-LogWriter or LOG4J-Appender that does this already before I go creating my own?
I can see http://sling.apache.org (org.apache.sling.scripting.core.impl.LogWriter) already does something similar, but will probably required me to hack the code out.
Thanks Jeff Porter
I did the same for log4j and logback; AFAIK, there is no ready-made solution.
For additional usefulness, my implementation buffers log messages on all levels and you can configure the number of messages to keep per level.
When an ERROR is logged, I dump all messages in order.
Some comments:
AtomicInteger
or AtomicLong
to give each message a unique ID. You will need that later to sort them into an order from the different buffers.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With