> On 2013/12/30, at 5:34, Joe <[email protected]> wrote: > > I found this post while looking for a solution for this problem: > > http://stackoverflow.com/questions/20819376/log4j2-rollingfile-appender-add-custom-info-at-the-start-of-each-logfile > > So, Ralph's statement makes me hope: >> You can already extend this class and override that method to perform work >> before or after doing super.rollover(fileManager). > > Ok, extending DefaultRolloverStrategy is looks easy, like this dummy try: > > > > But I stuck at two things: > - how to force the RollingFileAppender to use MyRolloverStrategy instead of > DefaultRolloverStrategy (seems that I have to deal with @Plugin and > @PluginFactory)?
Yes, that is correct. Your custom strategy needs to have a @Plugin annotation and a static factory method annotated with @PluginFactory. In the configuration file you'll specify your custom rollover strategy in a nested Strategy element of the RolloverAppender configuration. (See appender page in manual for example config. ) > - how to write to the logfiles within my rollover method? Instead of just executing a FileRenameAction like DefaultRolloverStrategy does, your action could do the rename, and create a new file with some data already saved. > > Could you help me at this point? > I would be happy to get some sample source snippets. > > Cheers, Joe > > Hope this helps to get you started. Best regards, Remko > > > -- > View this message in context: > http://apache-logging.6191.n7.nabble.com/log4j2-getting-started-rolling-files-tp8406p42402.html > Sent from the Log4j - Users mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
