logginglogbacksifting-appender

Logback - SiftingAppender with embeded DB Appender


I'm aware of SiftingAppener and its ability to separate logging events to individual logs files

Instead, can SiftingAppender separate logging events according to user sessions, so that the logs generated by every user go into ONE SQL insert statement (similar to FileAppender with One file)

Any ideas or suggestions on how to achieve this?

Please note the Row numbers

Before:

    TimeStamp       Formatted   Message     Logger_Name         Level_String
1   1321325688174   Step 2:     Then stop   com.test.Account    INFO
2   1321325687931   Step 1:     The force   com.test.Account    INFO

After:

    TimeStamp       Formatted   Message     Logger_Name         Level_String
1   1321325688174   Step 2:     Then stop   com.test.Account    INFO
    1321325687931   Step 1:     The force   com.test.Account    INFO

Thanks.


Solution

  • I'm not aware of any existing appender that would do this but it doesn't sound that hard to do yourself. You would need to implement your own appender class that extends AppenderBase and configure the SiftingAppender to use it.

    Inside of your new CachingSqlAppender (or whatever you call it) you would have to handle the temporary caching of all requests inside your appender and then at some prearranged interval write them all out.

    It seems though that this might be a difficult thing to get the timing right on because you'll have to figure out how long your appender waits for another event before doing the insert and it would have to at least be shorter than the lifespan that SiftingAppender gives the appenders it creates.