Here I am answering my own question, just in case someone else comes across the same problem. This is how I eventually did it (don't know however if it's the orthodox way):
Instead of extending AppenderSkeleton, I extended RollingFileAppender (to keep the rollover functionality), and overrode its openFile() method. In here I could manipulate the log file and write the header in it, after letting it do whatever it needed to do by default. Like this:
public void openFile(String fileName) throws IOException {
super.openFile(fileName);
File activeFile = new File(getFile());
if (activeFile.exists() && activeFile.isFile() && activeFile.length() == 0) {
FileUtils.writeStringToFile(activeFile, header);
}
}
I configured the header in logback.xml, as simple as this: <header> value </header>
. This injects it in the header field of my new appender.
Seems to work without problems, but please do post if you know a better way!