Using log4j2 (beta9) with java 1.7.
My complete log4j2.xml:
New solution available
Some time has passed since this question was asked, and now, when I wanted to do the same I have found out that it is possible to solve without messing with factories, but it was not easy to find. The log4j2 team have made it possible to do this by configuration. I hope my post will be of use and save time for someone else.
They have hidden this feature in the PatternLayout element. Not where I first looked, but why complain when it works?
This is my configuration (pay attention to header and footer, and the properties they use):
${sys:catalina.home}/logs/my-app
${log-path}/archive
[%d] [%-5p] [%t] %C{5} - %m%n
450
[%d] Start of log \n========================================================================\n
Will be archived in ${archive}\n\n
\n========================================================================\n[%d] End of log
As you can see I have included a timestamp, and a property, that includes a system property. Log4j2 can show many different kinds of properties, with this you can do a lot of things of what you asked for.
The log file looks like this:
[2016-08-09 17:00:43,924] Start of log
========================================================================
Will be archived in /home/emanciperingsivraren/program/apache-tomcat-8.0.32/logs/my-app/archive
[2016-08-09 17:00:44,000] [INFO ] [RMI TCP Connection(2)-127.0.0.1] [snip]
========================================================================
[2016-08-09 17:02:17,871] End of log
Do you need more custom information? - try to put that information in properties, system properties, or something else that log4j2 can read.
See Property Substitution in log4j2 for details in what kind of properties you can have.
Comments about the configuration