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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:36:54+00:00 2026-06-04T01:36:54+00:00

In the powerful logging built-in module in Python, it is possible to disable all

  • 0

In the powerful logging built-in module in Python, it is possible to disable all logs below a level by calling, for example, logging.disable(logging.INFO).

I did not find how to reset or undo this setting in the doc.

My purpose is to disable and re-enable info and debugging level logs when doing unittests, by calling logging.disable in setUp(), then calling (what?) in tearDown().

NB: I know how to do it if I have a give logger instance: keep logger.level, set the level higher, then set it back in tearDown(). I would prefer a way to mute all loggers without choosing them explicitly.

  • 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-06-04T01:36:56+00:00Added an answer on June 4, 2026 at 1:36 am

    It looks like the answer is to call logging.disable(logging.NOTSET)

    import logging
    
    logger = logging.getLogger('testlog')
    handler = logging.FileHandler('\\path\\to\\testlog.log')
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    logger.setLevel(logging.INFO)
    
    logger.error("some error occurred")
    logger.info('some info msg')
    logging.disable(logging.ERROR)
    logger.info('another info msg')
    logging.disable(logging.NOTSET)
    logger.info('last info msg')
    

    results in a log file with this output:

    2012-05-17 11:09:24,441 ERROR some error occurred
    2012-05-17 11:09:24,443 INFO some info msg
    2012-05-17 11:09:24,443 INFO last info msg
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One particular quirk of the (otherwise quite powerful) re module in Python is that
Does clojure have a powerful 'loop' like common lisp. for example: get two elements
Guava libraries are powerful, but I’m not sure what all the possibilities of this
What is powerful way to force a form to bring front of all the
git is a very powerful tool, but not that easy to use For example,
Which one is more powerful operating system? And is it possible to convert Microsoft-DOS
We are using asp.net 3.5 with c#.We have to make an powerful mailer module.This
What is the ideal code to logging ratio? I'm not used to writing logs
With powerful frameworks like jQuery, it seems to be possible to build an entire
Smartgrid component in web2py is very powerful. I wonder if it is possible to

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.