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 8001031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:58:49+00:00 2026-06-04T15:58:49+00:00

Context: I want to use log4j to write audit-related logs to a specific log

  • 0

Context:

I want to use log4j to write audit-related logs to a specific log file, let’s say audit.log. I don’t want to use syslogappender(udp based) because I don’t want to be tolerant to data loss. Plus, I am using logrotate to rotate the audit.log when the file gets to certain size.

Problem:

I am encountering is that, when logrotate rotates the file audit.log to audit.log.1, log4j keeps writing to audit.log.1 other than writing to the audit.log.

Possible approaches:

  1. I know I can use rollingfileappender to do the log rotation other than use logrotate, so when rollingfileappender rolls the file, it switch to the new file without hassles. But the reason I can’t use rollingfileappender is that I want to use logrotate’s post rotate feature to trigger some scripts after the rotation happens which can’t be provided by rollingfileappender.

  2. Another desperate way I can think of is to write a log4j customized appender myself to close the log file(audit.log.1) and open the new one(audit.log) when it detects the file is rotated.

  3. I never used ExternallyRolledFileAppender, but if it’s possible to use logrotate post rotate to send the signal to ExternallyRolledFileAppender and make log4j aware the file is rotated, and start writing to the new file?

Question:

Just wondering is there some appender like that already been invented/written? or do I have other options to solve this?

  • 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-04T15:58:50+00:00Added an answer on June 4, 2026 at 3:58 pm

    Check out logrotate‘s copytruncate option, it might help your case:

    copytruncate
           Truncate the original log file to zero size  in  place
           after  creating  a copy, instead of moving the old log 
           file and optionally creating a new  one.   It  can  be  
           used  when  some  program  cannot be told to close its 
           logfile and thus might continue writing (appending) to
           the  previous  log file forever.  Note that there is a
           very small time slice between  copying  the  file  and 
           truncating  it,  so  some  logging data might be lost.
           When this option is used, the create option will  have
           no effect, as the old log file stays in place
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Context Say, we want to use the Box-Muller algorithm. Starting from a couple of
Context I want to use JavaFx with clojure. I am aware of http://nailthatbug.net/2011/06/clojure-javafx-2-0-simple-app/ Question:
I want to use Context.Items to store some info of a User Control like:
I want to use the exclusive key to open context menu that are available
I've used mime_content_type() and File info but i never successed. i want to use
I have a bitmap image context and want to let this appear blurry. So
I want log4j to produce record-like output. What I DON'T want: 1 INFO ...
I want to use Spring Cache features but I don't know what dependedencies this
I'm currently trying to make Log4J log into a JTextPane . I want to
I want to let two classes communicate with each other. I want to use

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.