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

  • Home
  • SEARCH
  • 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 6704277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:16:12+00:00 2026-05-26T07:16:12+00:00

I have a logging problem with log4j. I am using the configureAndWatch to make

  • 0

I have a logging problem with log4j. I am using the configureAndWatch to make log4j poll the following config occasionnaly and update what logging is done:

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

    <!-- Write logs to a file -->
    <appender name="DEBUGGING" class="org.apache.log4j.RollingFileAppender">
        ...
    </appender>

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

    ...

    <category name="com.ourinternalpackage" additivity="false">
        <priority value="DEBUG"/>
        <appender-ref ref="CONSOLE"/>
    </category>

    <root>
        <level value="DEBUG"/>
        <appender-ref ref="CONSOLE"/>
    </root>

</log4j:configuration>

This works well. Everything I expect ends up getting logged to console. Now I add (before the root element):

    <category name="com.ourinternalpackage.somesubpackage.SomeClass" additivity="true">
        <priority value="DEBUG"/>
        <appender-ref ref="DEBUGGING"/>
    </category>

Now, as expected, the log messages from SomeClass ends up in both the DEBUGGING log file and is logged to console. Great! However, when I change the priority of the category named “com.ourinternalpackage.somesubpackage.SomeClass” to OFF the logging to CONSOLE is also disabled. This is unexpected since the category named “com.ourinternalpackage” still has it’s priority set to DEBUG and is logging to console. Other debug level messages, from classes in the com.ourinternalpackage, do end up in the console log. Additionally, if I remove the category with the appender-ref to DEBUGGING from the config file it keeps appending debug messages to the log.

Any ideas how to be able to toggle the logging on AND off for a specific category/logger without having to restart the application? In most cases the priority level for the category with name “com.ourinternalpackage” would be set to INFO. In which case I could set the priority of the category named “com.ourinternalpackage.somesubpackage.SomeClass” to INFO to reduce the ammount of logging done, but I would still be logging to both files. Which is something I’d like to avoid if possible.

  • 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-26T07:16:12+00:00Added an answer on May 26, 2026 at 7:16 am

    Any ideas how to be able to toggle the logging on AND off for a specific category/logger without having to restart the application?

    In the paragraph right before that, you said that you already did that by setting the priority to “OFF”.

    If I understand you correctly, then everything you described is expected log4j behavior. You should spend some time in the log4j manual to understand how loggers and appenders work. You seem to incorrectly expect that the same logger can be configured to have two different priorities/levels. That’s not how it works. If you have specific questions other than that one that I quoted, ask them explicitly.

    Update: Based on your update, you still need to read the log4j manual. (It’s really short and easy to read.) You have a Logger named “com.ourinternalpackage.somesubpackage.SomeClass”. There’s only one of them, and whether you list it explicitly in the config file or not, it exists because somewhere your code calls or causes to be called Logger.getLogger(SomeClass.class).

    Your one Logger can only have one priority. When you define <category name="com.ourinternalpackage.somesubpackage.SomeClass" ..., its priority comes from there because it’s an exact match to the Logger. If you don’t define the exact match, then your Logger inherits its priority from its nearest ancestor, which is <category name="com.ourinternalpackage" .... Thus when you add the exact match and set it to “OFF”, the expected (and exhibited) behavior is for all output of that Logger to be turned off.

    So, still, the answer to your question is, “You’re already doing it.” That is, you’re already toggling logging on and off for a specific Logger. It’s just that you have an incorrect concept of what a Logger is. You think you have two Loggers when you only have one. One possible solution to your problem would be to actually create two Loggers. Then you can control them individually the way you’re trying to. If you create one named “com.ourinternalpackage.somesubpackage.SomeClass” and one named “debug.com.ourinternalpackage.somesubpackage.SomeClass”, then you’ve established a precedent for prefixing debug Loggers with “debug”, and you can control your entire set of debug Loggers with one config entry: <category name="debug" ....

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

Sidebar

Related Questions

I have the following logging problem with several Java applications using log4j for logging:
I have a problem logging onto a page and then using it with cURL.
I have a small problem using log4j and FileAppender . When I am using
I have a peculiar problem with Log4j. We are deploying on Weblogic 10 using
I have a stupid java logging problem: I'm loading the logging configuration from my
In my django project I have following LOGGING config: LOGGING = { 'version': 1,
I'm using Castle for logging facade. I have problem when my logger is logging
I have a problem wih a logging setup in a apring webapp deployed under
I have a problem, I would like to build logging system which will be
I have the following need I have a logging table which logs som leads

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.