Thanks Ceki! I knew I could count on you replying quickly. The framework here is the auditing framework I constructed some 1,5 years ago for a customer. They've now realized this requirement.
I was kind of hoping that I could add some step before the layout gets the event. In that step, I could check the event, and if necessary split it into x events. And then the layout would get these n events instead and do the normal logging on each of them. I had a look at the filters, but they only handle allow/block kind of things. This would be some other kind of "filter". Maybe there's no advantage going down this path compared to your suggestion... /Anders On Tue, Sep 22, 2009 at 11:38, Ceki Gulcu <[email protected]> wrote: > > Hello Anders, > > Logback-core? Nice. > > If only the field 'foo' needs to be split, then just override the converter > for the field foo to do the splitting, and you are done. However, you > requirements differ as you also require the repetition of other fields. > > The approach which seems the most logical to me, would be to derive a > sub-class from PatternLayoutBase overriding the writeLoopOnConverters method > so that when the foo field needs splitting, you would loop over the > converter chain as many times as necessary. > > Here is a possible implementation: > > class MyPatternLayout extends PatternLayoutBase<MyEvent> { > > ... > > protected String writeLoopOnConverters(MyEvent event) { > Foo foo = event.getFoo(); > StringBuilder sb = new StringBuilder(); > String[] fooParts = split(foo); > for(String s: fooParts) { > // construct a new event from 'event' so that foo has only one part > MyEvent splitEvent = new MyEvent(event, s); > String line = super.writeLoopOnConverters(splitEvent); > sb.append(line); > sb.append(CoreConstants.LINE_SEPARATOR); > } > return sb.toString(); > } > } > > HTH, > > > Anders Hammar wrote: > >> Hi, >> >> I have a framework that utilizes logback-core for logging. Due to >> limitations in the software reading the log files, a new requirement is that >> long data should be split on multiple rows. I'm trying to figure out if >> there a simple way of doing this? >> >> More info: What I have is an extension of the PatternLayoutBase which adds >> the converters for my event class. I'm using the standard >> RollingFileAppender. So, let's say I have a FooConverter, which gets the foo >> info from the event. But, when logging to the file, the foo info part must >> never be longer than x chars. If it is, it should be split on multiple rows. >> Other data (generated by other converters) should then be repeated. >> >> Any suggestions on how to do this in a clean logback way is appreciated! >> What I'm currently thinking is to loop on the converters (calling >> PatternLayoutBase.writeLoopOnConverters multiple times), but I need to know >> when that's required... Anyone done something similar? >> >> /Anders >> >> > -- > Ceki Gülcü > Logback: The reliable, generic, fast and flexible logging framework for > Java. > http://logback.qos.ch > _______________________________________________ > Logback-user mailing list > [email protected] > http://qos.ch/mailman/listinfo/logback-user >
_______________________________________________ Logback-user mailing list [email protected] http://qos.ch/mailman/listinfo/logback-user
