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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:39:20+00:00 2026-05-25T23:39:20+00:00

I was wondering how to implement a global logger that could be used everywhere

  • 0

I was wondering how to implement a global logger that could be used everywhere with your own settings:

I currently have a custom logger class:

class customLogger(logging.Logger):
   ...

The class is in a separate file with some formatters and other stuff.
The logger works perfectly on its own.

I import this module in my main python file and create an object like this:

self.log = logModule.customLogger(arguments)

But obviously, I cannot access this object from other parts of my code.
Am i using a wrong approach? Is there a better way to do this?

  • 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-25T23:39:20+00:00Added an answer on May 25, 2026 at 11:39 pm

    Use logging.getLogger(name) to create a named global logger.

    main.py

    import log
    logger = log.setup_custom_logger('root')
    logger.debug('main message')
    
    import submodule
    

    log.py

    import logging
    
    def setup_custom_logger(name):
        formatter = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(module)s - %(message)s')
    
        handler = logging.StreamHandler()
        handler.setFormatter(formatter)
    
        logger = logging.getLogger(name)
        logger.setLevel(logging.DEBUG)
        logger.addHandler(handler)
        return logger
    

    submodule.py

    import logging
    
    logger = logging.getLogger('root')
    logger.debug('submodule message')
    

    Output

    2011-10-01 20:08:40,049 - DEBUG - main - main message
    2011-10-01 20:08:40,050 - DEBUG - submodule - submodule message
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`ve been wondering how to implement methods in a class. Could someone explain me
I was wondering if anyone could tell me how to implement line 45 of
I am wondering why when I declare a public Int that I implement everytime
I was wondering how to implement the following problem: Say I have a 'set'
I'm wondering whether I could implement a Chrome style proces model with a WPF
I was wondering if anybody could give insight on how to implement the window
I'ver been wondering how to best implement equals() for a family of classes that
I was wondering if anyone could help me implement color selection in my iOS
I'm wondering why I have never seen the following way to implement templates in
I'm wondering how to implement what is stated in the title. I've tried something

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.