
There is some info on markers at http://logback.qos.ch/demo.html Here is the general structure I had in mind. package ch.qos.logback.demo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.Marker; import org.slf4j.MarkerFactory; public class MarkerExample { static Marker START = MarkerFactory.getMarker("START_SECTION"); static Marker STOP = MarkerFactory.getMarker("STOP_SECTION"); Logger logger = LoggerFactory.getLogger(MarkerExample .class); public void aMethod() { logger.info(START, "Hello world"); doSomething(); logger.debug("Just did something"); try { doSomethingElse(); } catch(Exception e) { logger.debug("that did not go so well...", e); } logger.info(STOP, "that's it folks"); } } In your appender, you would start buffering when you saw a START_SECTION marker and throw away your buffer as soon as you saw a STOP_SECTION marker unless an error occurred. Outside of a section, you would log normally. Does this help? Eric Faden wrote:
Interesting. Is there an example of this somewhere?
-Eric
Ceki Gulcu wrote:
Hello Eric,
The logback and log4j share the same basic architecture. In principle, anything you can do in log4j you can do in logback. Rewriting a log4j appender in logback should be a 15 minute endeavor.
You can take advantage of logback markers so that you can mark the begging and an end of a section (however long). If the section end without any errors you ditch the buffered events. Otherwise, if an error occurs, you log them.
This is very similar to your test function, except that markers give you a way to indicate the start and the end of buffering.
Cheers,
-- Ceki Gülcü