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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:54:40+00:00 2026-06-08T03:54:40+00:00

In my current project I need to make a certain task create its own

  • 0

In my current project I need to make a certain task create its own logfile separate from what is configured in log4j.properties.

I try to achieve this by attaching a dynamically created FileAppender to the rootLogger:

public static void setupAnalysisLogfile(String filename) {
  PatternLayout layout 
           = new PatternLayout("%d{dd MMM yyyy HH:mm:ss,SSS} [%t] %-5p %C{1} %x - %m%n");
  if(Config.CREATE_SEPERATE_LOG)
  {
     FileAppender appender;
     try {
       String path = (Config.LOGFILE_PATH!=null)?Config.LOGFILE_PATH:filename;
       appender = new FileAppender(layout,path);
       appender.setName("Analysis Appender");
       org.apache.log4j.Logger.getLogger("my.package.hierarchy").addAppender(appender);
     } catch (IOException e) {
       org.apache.log4j.Logger.getLogger(Config.class).warn(
                                                      "Failed to create a dedicated log "
                                                      + filename, 
                                                      e);
     }
   }        
}

When Config.LOGFILE_PATH is not null (comes from a commandline parameter) everything works. The logfile is created in the specified path.

However, when LOGFILE_PATH is null no logfile is created, or rather nothing is ever written to it.

Running the program with -Dlog4j.debug gives:

log4j: setFile called: /home/tbender/.something/bytecode/OMFG_3527961e3fb1134e1d3221c000879a90ff1022b6/bytecode/OMFG-1340994475441.log, true
log4j: setFile ended

When I step through the code and keep an eye on the list of open filehandles, I can see that the filehandle is created during the creation of the appender. Once the application finishes no logfile exists.

Any ideas?

  • 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-08T03:54:41+00:00Added an answer on June 8, 2026 at 3:54 am

    Okay in the end it was not FileAppend that caused to problem but a totally unrelated piece of code that deleted and recreated the folder where my logfile was residing. D’OH!

    Good tip for trouble like this: When you are in linux use strace:

    strace -tt -f -e trace=create,open,close,unlink -o strace.out java -jar yourjar.jar
    

    That will show you what files were created, oepened, closed or removed. You can also include a bunch of other stuff. More calls can be found here

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

Sidebar

Related Questions

In my current project (presentation, slide software) I need to be able to make
for my current project i need to consume messages from many destinations (from hundreds
I need to create high quality icons for my current project in vb.net This
In a current project i need to display PDFs in a webpage. Right now
Successfully used jquery-infinite-carousel in the past but for my current project I need it
I need to implement for current project some secure login in php. I wrote
For our current J2EE project based on JBoss, we need to interface with a
My current project has a development web server and live web server. Developers make
For my current project, I want to dynamically load routes from a database. For
Current project: To make a time program in C# with two classes Time and

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.