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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:18:21+00:00 2026-06-16T21:18:21+00:00

I have a java project(note:- its not a web project).I am using log4j to

  • 0

I have a java project(note:- its not a web project).I am using log4j to log messages.

Presently the steps I am following to do it are as follows:

  • Created a log4j.properties file at project level.

  • Declared Logger logger = Logger.getLogger(MyClass.class);

  • Then configured properties using -> PropertyConfigurator.configure(“log4j.properties”);

  • Then used logger.debug(“message”); to log my messages.

But the problem I felt with this approach is that I have to do the same in all the classes in my project i.e. from all the steps starting from declaring Logger logger.

Is there any way so that I can configure my logger variable at a single place only once in my project and then just use the declared variable of logger to log the messages?

  • 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-16T21:18:22+00:00Added an answer on June 16, 2026 at 9:18 pm

    IMHO You should not have a common logger for normal logging purposes. Each class should create its own logger by Logger logger = Logger.getLogger(MyClass.class);. This might seem to be an overhead when you have few class files, but it will be better to follow this.
    By following this pattern of loggers you get the flexibility of controlling the level of logging at any level (whole application or any package or any class) at the configuration level(in log4j.properties).

    You can give log4j.properties in your classpath and log4j will automataically pick it up.
    PropertyConfigurator.configure("log4j.properties"); is not required.

    Still if you want to do it, You can create your own logger class MyLogger with static methods for logging which will wrap the actual call to the logger. Then from your individual classes you can call MyLogger.log() or MyLogger.debug() to log.

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

Sidebar

Related Questions

I have a Java project connecting to an Ingres database and using the Spring
I have a Java project that I build using an Ant script. I am
I have a project with mixed Java and Scala sources, following the instructions on
I have the following import in my java code in an eclipse project import
I have a Java Project , for which I'm now creating a Web interface,
I have an Eclipse project with the following directory structure: MyProj/ src/main/java/ com.me.myproject.widgets Widget.java
I have a Java Web Services project that was created in an older version
I have developed a simple Apache-Axis java web service using Eclipse IDE and now
I have to give a general note to some huge Java project for which
I have a java project that uses JPA 2/Hibernate 3.5.6 for data access 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.