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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:29:35+00:00 2026-05-11T00:29:35+00:00

In Django, I’ve got loggers all over the place, currently with hard-coded names. For

  • 0

In Django, I’ve got loggers all over the place, currently with hard-coded names.

For module-level logging (i.e., in a module of view functions) I have the urge to do this.

log = logging.getLogger(__name__) 

For class-level logging (i.e., in a class __init__ method) I have the urge to do this.

self.log = logging.getLogger('%s.%s' % (     self.__module__, self.__class__.__name__)) 

I’m looking for second opinions before I tackle several dozen occurrences of getLogger('hard.coded.name').

Will this work? Anyone else naming their loggers with the same unimaginative ways?

Further, should I break down and write a class decorator for this log definition?

  • 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. 2026-05-11T00:29:36+00:00Added an answer on May 11, 2026 at 12:29 am

    I typically don’t use or find a need for class-level loggers, but I keep my modules at a few classes at most. A simple:

    import logging LOG = logging.getLogger(__name__) 

    At the top of the module and subsequent:

    LOG.info('Spam and eggs are tasty!') 

    from anywhere in the file typically gets me to where I want to be. This avoids the need for self.log all over the place, which tends to bother me from both a put-it-in-every-class perspective and makes me 5 characters closer to 79 character lines that fit.

    You could always use a pseudo-class-decorator:

    >>> import logging >>> class Foo(object): ...     def __init__(self): ...             self.log.info('Meh') ...  >>> def logged_class(cls): ...     cls.log = logging.getLogger('{0}.{1}'.format(__name__, cls.__name__)) ...  >>> logged_class(Foo) >>> logging.basicConfig(level=logging.DEBUG) >>> f = Foo() INFO:__main__.Foo:Meh 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

django guardian https://github.com/lukaszb/django-guardian is a really well written object-level permissions app; and I have
Django has an excellent support for internationalization, any English expression within Models, Forms, View
Django newbie here, I need to do a count over a certain filter in
Django stated in their docs that all query sets are automatically cached, https://docs.djangoproject.com/en/dev/topics/db/queries/#caching-and-querysets .
Django view points to a function, which can be a problem if you want
[Django 1.0.2] I have a view set up like this: (r'^redirect/(?P<object_id>\d+)/(?P<url>.*)/$', 'django.views.generic.simple.redirect_to', {'content_type': SiteType},
Django's views documentation states that the default 500 view passes no variables to this
Django development server is really nice, it shows the log of all POST/GET requests
Django is telling me that my login view isn't returning an HttpResponse object: The
Django has the concept of filters that allow you to format values in views.

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.