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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:21:37+00:00 2026-06-14T09:21:37+00:00

In my application I read in an inputfile (e.g. myFile1.txt) and create an outputfile

  • 0

In my application I read in an inputfile (e.g. myFile1.txt) and create an outputfile with the same name (e.g. myFile2log). Point is that the inputfile will be read within the java application and not given as command line parameter. Therefore it is required to set an appender in the application, e.g.

public class Example {
private static final Logger LOG = Logger.getLogger(Example.class);

public Example() throws IOException {
    FileAppender appender = new DailyRollingFileAppender(new PatternLayout(
            PatternLayout.DEFAULT_CONVERSION_PATTERN), "yourfilename.log",
            "'.'yyyy-MM-dd");
    LOG.addAppender(appender);
    LOG.setLevel((Level) Level.DEBUG);
    LOG.debug("blabla");

    new RandomClass();
}

public static void main(String[] args) throws IOException {
    new Example();
}
}

public class RandomClass {
private static final Logger LOG = Logger.getLogger(RandomClass.class);

public RandomClass() {
    LOG.debug("hello Randomclass");
}
}

And here is the problem: if I do the above the custom file appender only works for the specific class where the fileappender was defined, but not on any other class. Therefore the output of the “RandomClass” will not be written into this logfile, but which is what is required. How can I achieve that?

  • 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-14T09:21:38+00:00Added an answer on June 14, 2026 at 9:21 am

    If you would like to set the appender dynamically you should try setting the new appender to the root logger:

    Logger logger = Logger.getRootLogger();
    FileAppender appender = new DailyRollingFileAppender(new PatternLayout(
       PatternLayout.DEFAULT_CONVERSION_PATTERN), "yourfilename.log", "'.'yyyy-MM-dd");
    logger.addAppender(appender)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I make android application that read textfile.txt from resource/raw. And it's work fine. Here
I'm writing a Java ME application that uses iText to read PDF. When I
I have developed an application that read how many files are there in a
I have an application that read an online xml file, now i want to
I'm trying to write a Java application that manipulates high resolution .wav files. I'm
I created a java program that would just read a webpages code... google's for
I'm trying to have my application read through a text file and look for
i have developed application for read information from card reader. Here i have used
I created one application to read all the contacts stored in android 2.0 emulator.I
I have my application to read and display an ePub file almost ready. What

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.