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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:34:59+00:00 2026-06-11T11:34:59+00:00

I am trying to capture the logs using log4j in Java. The executeable is

  • 0

I am trying to capture the logs using log4j in Java. The executeable is in linux envirnment and it displays the logging message, however, it is not writing into the log file. I am using log4j.xml and this is what I have so far

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

  <appender name="LocalFileAppender" class="org.apache.log4j.RollingFileAppender">
    <param name="File"   value="logs/error.log" />
    <param name="Append" value="true" />
    <param name="MaxFileSize" value="500KB" />
    <param name="maxBackupIndex" value="1" />
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d %-5p [%c] - %m%n"/>
      </layout>
  </appender>

  <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.SimpleLayout"/>
  </appender>

  <root>
    <priority value ="Debug" />
    <appender-ref ref="console" /> 
  </root>
</log4j:configuration>

I am not clear how the java program knows where the xml file is located. I think that is the problem. And, this is how I setup in the code,

log = Logger.getLogger(MyClass.class);

BasicConfigurator.configure();

Any help would be appreicate it. Thanks.

  • 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-11T11:35:00+00:00Added an answer on June 11, 2026 at 11:35 am

    You can place the log4j.xml file on the classpath of your application and log4j will find it automatically to configure itself with the very first time you use log4j.

    However, by calling BasicConfigurator.configure(), you are undoing any configuration done by the XML file – as this sets up a console appender to the root logger only.

    Run your java program with -Dlog4j.debug to have log4j output a bunch of information about where it is looking for the configuration files when it starts up.

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

Sidebar

Related Questions

i'm trying to capture/play audio with java in linux with pulseaudio server. there's no
I am trying to capture the right part after the : using java expr,
I trying to capture packets using SharpPcap library. I'm able to return the packets
I'm trying to capture audio, using the method in this question ; with AVCaptureSession
I'm new here. I have been trying to create a video capture app using
I am trying to capture an image of the WebView component as it displays
I'm trying to capture logging messages, stdout, and stderr for my webapp, which is
I am trying to capture img tag in HTML using Regex... So these must
I'm trying to capture an image using Android Camera via simple activity. Image is
I'm trying to capture a UILabel's height in an instance variable. I'm using a

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.