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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:21:06+00:00 2026-05-29T22:21:06+00:00

I was trying to create a custom attribute for logging (caller’s class name, module

  • 0

I was trying to create a custom attribute for logging (caller’s class name, module name, etc.) and got stuck with a strange exception telling me that the LogRecord instance created in the process did not have the necessary attributes. After a bit of testing I ended up with this:

import logging

class MyLogger(logging.getLoggerClass()):
    value = None

logging.setLoggerClass(MyLogger)

loggers = [
    logging.getLogger(),
    logging.getLogger(""),
    logging.getLogger("Name")
]

for logger in loggers:
    print(isinstance(logger, MyLogger), hasattr(logger, "value"))

This seemingly correct piece of code yields:

False False
False False
True True

Bug or feature?

  • 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-29T22:21:06+00:00Added an answer on May 29, 2026 at 10:21 pm

    Looking at the source code we can see the following:

    root = RootLogger(WARNING)
    def getLogger(name=None):
        if name:
            return Logger.manager.getLogger(name)
        else:
            return root
    

    That is, a root logger is created by default when the module is imported. Hence, every time you look for the root looger (passing a false value such as the empty string), you’re going to get a logging.RootLogger object regardless of any call to logging.setLoggerClass.

    Regarding the logger class being used we can see:

    _loggerClass = None
    def setLoggerClass(klass):
        ...
        _loggerClass = klass
    

    This means that a global variable holds the logger class to be used in the future.

    In addition to this, looking at logging.Manager (used by logging.getLogger), we can see this:

    def getLogger(self, name):
        ...
                rv = (self.loggerClass or _loggerClass)(name)
    

    That is, if self.loggerClass isn’t set (which won’t be unless you’ve explicitly set it), the class from the global variable is used.

    Hence, it’s a feature. The root logger is always a logging.RootLogger object and the other logger objects are created based on the configuration at that time.

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

Sidebar

Related Questions

hi i am trying to create a custom attribute for my MVC application so
I'm trying to create a custom module using Magento's EAV structure and have been
I'm trying to create a custom class for my pages in my project. Here's
I'm trying to create a custom attribute for each list item in a databound
I'm trying to create a custom exception handler for the exception handling block of
I'm trying to create a custom attribute called Tag for all editable elements. I
I'm trying to create a custom attribute validation for a webform projects. I already
I'm trying to show custom error messages without the attribute name in front. I
I've create a custom attribute for my web pages... In the base page class
I'm trying to create a custom attribute that will work in a sort-of AOP

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.