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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:42:53+00:00 2026-05-13T10:42:53+00:00

The Java docs for Logger indicate that the logger name should be based on

  • 0

The Java docs for Logger indicate that the logger name should be based on the class name. Google Guice handles this in BinderImpl.java where it does the following:

return member == null
      ? Logger.getAnonymousLogger()
      : Logger.getLogger(member.getDeclaringClass().getName());

However, since it’s getting a new logger for each class, I would lose access to whatever Handler’s may have been added to my logger.

What’s the best way to handle both having the class name used within the logger and having a standard set of handlers applied?

  • 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-13T10:42:53+00:00Added an answer on May 13, 2026 at 10:42 am

    The solution actually has nothing to do with Guice, but rather, is based on how the logging classes work in Java.

    Loggers are created in a hierarchy, thus, logger x.y.z is a child of x.y, all the way up the chain to the root logger whose name is the empty string. Each logger inherits properties, like its logging level, from its parent.

    Thus, in order to set the log level globally (or to set handlers globally), simply set them on the root logger:

    LogManager logManager = LogManager.getLogManager();
    Logger rootLogger = logManager.getLogger("");
    rootLogger.setLevel(Level.FINEST);
    rootLogger.addHandler(new ConsoleHandler());
    

    Once that’s done, any injected loggers will have their properties derived from the root logger and any parent loggers that may exist. For more information on the basics, see the LogManager documentation.

    A config property also exists. Per the LogManager documentation:

    A property “config”. This property is
    intended to allow arbitrary
    configuration code to be run. The
    property defines a whitespace or comma
    separated list of class names. A new
    instance will be created for each
    named class. The default constructor
    of each class may execute arbitrary
    code to update the logging
    configuration, such as setting logger
    levels, adding handlers, adding
    filters, etc.

    This implies that there are multiple solutions to the problem as I could have also used a configuration class.

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

Sidebar

Ask A Question

Stats

  • Questions 300k
  • Answers 300k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your best bet is to use something like Firebug or… May 13, 2026 at 7:59 pm
  • Editorial Team
    Editorial Team added an answer Will you prevent XSS attacks? If you do this escaping… May 13, 2026 at 7:59 pm
  • Editorial Team
    Editorial Team added an answer You can start by taking a look at the chat… May 13, 2026 at 7:59 pm

Related Questions

I would like to configure a DataSource using JNDI in a Java SE app.
I have an existing application which does all of its logging against log4j. We
I have a use case where a servlet (that has reasonably high concurrent use)
The Java Docs for the method String[] java.io.File.list(FilenameFilter filter) includes this in the returns
Suppose I have an interface: public interface FooInterface { public void someMethod(); } and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.