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 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

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Use a DPI of 96. WPF is scaling your image… May 11, 2026 at 11:11 am
  • added an answer From the MSDN site the Calendar..::.OnDayRender Method is invoked while… May 11, 2026 at 11:10 am
  • added an answer The CPAN module Net::Google::Search implements Google's SOAP API for searching. May 11, 2026 at 11:10 am

Related Questions

In Django, I've got loggers all over the place, currently with hard-coded names. For
Coming from a background in Django, I often use template inheritance, where multiple templates
Say I have a blogging app in Django. How can i re-order the posts
I'm developing a website (in Django) that uses OpenID to authenticate users. As I'm
I'm writing a url rewrite in django that when a person goes to http://mysite.com/urlchecker/http://www.google.com
I'm working on a blog application in Django. Naturally, I have models set up
I'm trying to make some types in Django that map to standard Django types.
I know you can specify fieldsets in django for Admin helpers. However, I cannot
I'm taking a look at how the model system in django works and I
How can i clean and modify data from a form in django. I would

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.