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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:16:37+00:00 2026-06-13T07:16:37+00:00

If my log4j.properties looks this # General configuration log4j.rootLogger = ERROR, ConsoleAppender # Appender

  • 0

If my log4j.properties looks this

# General configuration
log4j.rootLogger = ERROR, ConsoleAppender

# Appender configuration
log4j.appender.ConsoleAppender = org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleAppender.layout = org.apache.log4j.PatternLayout 
log4j.appender.ConsoleAppender.layout.ConversionPattern = %5p (%c) %m%n
#Other Loggers
log4j.logger.com.foo=INFO
log4j.logger.com.foo.Bar=DEBUG
log4j.logger.org.springframework=INFO

Is there an easy way to get just the loggers com.foo, com.foo.Bar, root, and org.springframework. And not the specific classes that have been created and inherit the levels (I.E. com.foo.bar.Baz?
For my purposes I want to create an admin page that displays these loggers and their levels, but not ALL loggers, just the ones that have been directly configured via properties. currently, I am traversing up the parent hierarchy until I come across a logger that has a different level that its parent, but that can hide some configured loggers if they are in the hierarchy and set the same level as something higher up.

  • 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-13T07:16:38+00:00Added an answer on June 13, 2026 at 7:16 am

    You could do something like this. First get all loggers from the log manager:

    Enumeration<Category> loggers = LogManager.getCurrentLoggers();
    

    Then you can ask each logger for its level:

    Level currentLevel = logger.getLevel();
    

    currentLevel will be null if it has never been explicitly set. So, if the logger was set to a specific level in log4j.properties, you will get a non-null value. Else you will get a null value. The root logger always reports a level, so that would be a special case. This way, you would not need to parse the log4j.properties file.

    The only problem is that if somewhere in your code you invoke setLevel() on a logger, it will also report non-null and appear on your list. That is because log4j does not know how a level was set, only if it was set at all. To distinguish these two cases, you would still need to parse log4j.properties.

    Also, keep in mind that this works only on loggers which are currently loaded. So if com.foo.Bar was never loaded, you will not see it on your list even if it is explicitly mentioned in log4j.properties. Log4J does not know about non-existing loggers which might be created in the future. Again, for this you would need to parse log4j.properties.

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

Sidebar

Related Questions

My log4j.properties file - log4j.rootLogger=INFO, stdout # =============== console output appender ===================== log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
I have the following log4j.properties file: log4j.rootLogger=DEBUG,A1,A2,A3 log4j.appender.A1=org.apache.log4j.RollingFileAppender log4j.appender.A1.Threshold=DEBUG log4j.appender.A1.File=log.out log4j.appender.A1.MaxFileSize=100KB log4j.appender.A1.MaxBackupIndex=1 log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%p
Here is my log4j.properties file # Set loggers' levels log4j.rootLogger=warn, trace_file # Appender log4j.appender.trace_file=org.apache.log4j.RollingFileAppender
I have this Log4j.properties with me log4j.rootCategory=Info, A1 # A1 is a DailyRollingFileAppender log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
I've set my log4j.properties file to this configuration below log4j.rootLogger=INFO, CATALINA # Define all
My log4j.properties file looks like this: # Root logger option log4j.rootLogger=DEBUG, file # Direct
I have the following on my log4j.properties log4j.rootLogger = debug, stdout, fileLog log4j.appender.stdout =
I've encountered the following bug: http://issues.apache.org/jira/browse/AXIS2-4363 It states the following: This error only occurs
I implemented log4j logging in my JSF application.My log4j.properties file is like this log4j.rootLogger=DEBUG,
I am trying to create 2 log files using log4j using this configuration: log4j.rootLogger=debug,stdout,logfile

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.