Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:25:04+00:00 2026-06-14T12:25:04+00:00

The functionality that I need is writing a header line at the beginning of

  • 0

The functionality that I need is writing a header line at the beginning of the configured log file. The log file should, in addition, get rolled over based on a time pattern (I’m talking logback 1.0.7).

So, I’m thinking of writing an Appender – although I’m not sure whether it’s not a custom Layout that I actually need.

1) Appender

Per logback’s documentation, the right approach is to extend AppenderSkeleton, but then how would I combine this with the RollingFileAppender (to make the file rollover?)

On the other hand, if I extend RollingFileAppender, what method do I override to just decorate the existing functionality? How do I tell it to write that particular String only at the beginning of the file?

2) Layout

Analogously, the approach seems to be extending LayoutBase, and providing an implementation for doLayout(ILoggingEvent event).
But again, I don’t know how to just decorate the behaviour – just adding a new line in the file, rather than disrupting its functionality (because I still want the rest of the logs to show up properly).

The getFileHeader() in LayoutBase looks promising, but how do I use it? Is it even intended to be overridden by custom layouts? (probably yes, since it’s part of the Layout interface, but then how?)

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:25:06+00:00Added an answer on June 14, 2026 at 12:25 pm

    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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an Eclipse plugin for the JDT. I need a functionality that tracks
I have some functionality that I need in all my classes which derive from
I have common functionality that I need to access from all screens of my
I am developing an IOS app. I need a functionality that includes undo and
I need to add functionality to the close button in my class that extends
i need to add some functionality to an asp.net application that allows the positioning
I need to access functionality from win32 dll , for that I am using
I need to add DVD writing functionality to an application I'm working on. However
I am writing an Android application that uses some functionality that has been published
im writing a chrome extension and need a simple text editor component so that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.