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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:05:18+00:00 2026-05-27T21:05:18+00:00

My Application is using logging in two manner….1) programatic 2) log4j.xml I have to

  • 0

My Application is using logging in two manner….1) programatic 2) log4j.xml
I have to create the logs files in two ( 1 using programatic and other using log4j.xml ) locations.

Programatic way ( have one more properties file in which all the things are mention like log level and all….lets say..thorugh this…file is getting created..name as “SAS_VP.log”) :

 Enumeration loggers = Logger.getRootLogger().getLoggerRepository().getCurrentLoggers(); 
  ......
  Logger temp = (Logger)iter.next();                                                
  temp.setLevel(level);

log4j.xml

  <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
  <param name="File" value="/LOGS/SAM/SAM_VJ.log"/> 
  <param name="Threshold" value="DEBUG"/>
  <param name="MaxFileSize" value="10000KB"/>
  <param name="MaxBackupIndex" value="10"/>
  <param name="Append" value="false"/>

 <layout class="org.apache.log4j.PatternLayout">

  <param name="ConversionPattern" value="%d{dd MMM yyyy HH:mm:ss,SSS} [%t] %5p [%F(% M):%L] %m%n"/>

 </layout>   

 </appender>


 <root>
 <appender-ref ref="CONSOLE"/>
 <appender-ref ref="FILE"/>
 </root> 

ISSUE :

Log level which i set programatically overwrite the log level of log4j.xml.Like in log4j.xml is have set the level “Debug” and Programatically I have set the level as “ERROR” then the file (SAM_VJ.log) which is created by log4j.xml only contains ERROR level logs.

How to solve this issue…I want that…my both logging ( programmatic and log4j ) should be indepedent.

Is there anything in log4j in which…if i have set the log level of package “com.sas” is “Debug” then nobody can modify that…something like mutable type

 <logger name="com.sam">    
<priority value="DEBUG"/>
 </logger>

Looking for your suggesstion….

  • 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-05-27T21:05:19+00:00Added an answer on May 27, 2026 at 9:05 pm

    I’m not sure you should really ask for such a functionality.
    You’re talking about a way to configure the log4j framework, and yes, it supports 3 different ways of configuration:

    1. properties file
    2. xml configuration
    3. programmatically, via your java code

    Its ok to me that the programmatic configuration allows to change the configured state of log4j loggers/appenders whatsoever.

    Your xml configuration should be loaded during the system startup, and then you apply your java code that overrides the configuration.

    If you have a logic of supplying a configuration in Java, why don’t you improve your logic and define an error level (from your example) only if you really wish to do it.

    Its impossible to configure the same logger to work both with DEBUG level (and up) AND ERROR level (and up).

    This is a feature in fact, and not a drawback, since it allows to change the behavior of LOG4j on the running system (without a restart) which is useful for issue tracking.

    Of course you can WRAP your loggers so that they won’t allow setLevel, but, I really don’t see why would you do that.

    Hope, this helps

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

Sidebar

Related Questions

I'm trying to get logging enabled on my application using Fluent NHibernate and log4net.
I am using Apache Common Logging in Desktop Application. private static final Log log
I'm using log4net for logging (duh!). Using the EventLogAppender, I can configure my application
We're using ELMAH for error logging in our ASP.NET application. We use the SQL
I am using logback/slf4j to handle logging in my application. Everything was working perfectly
I am considering using Postsharp framework to ease the burden of application method logging.
I'm looking at adding logging to an application, and I'm considering using Kiwi syslogd
I have a web application using ASP.NET 2.0 and I want to know if
I am developing an application using MVC Preview 5. I have used typed views.
I'm configuring the logging for a Java application. What I'm aiming for is two

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.