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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:55:25+00:00 2026-05-12T18:55:25+00:00

In Python 2.4 and later, configuring the logging module to have a more basic

  • 0

In Python 2.4 and later, configuring the logging module to have a more basic formatting is easy:

logging.basicConfig(level=opts.LOGLEVEL, format=”%(message)s”)

but for applications which need to support Python 2.3 it seems more difficult, because the logging API was overhauled in Py2.4. In particular, basicConfig doesn’t take any arguments. Trying a variation on the sole example in the Py2.3 documentation, I get this:

try:
    logging.basicConfig(level=opts.LOGLEVEL, format="%(message)s")
except:
    logging.getLogger().setLevel(opts.LOGLEVEL)
    h = logging.StreamHandler()
    h.setFormatter(logging.Formatter("%(message)s"))
    logging.getLogger().addHandler(h)

but calling this root logger in Py2.3, e.g.

logging.info("Foo")

gives duplicated output:

Foo
INFO:root:Foo

I can’t find a way to modify the format of the existing handler on the root logger in Py2.3 (the “except” block above), hence the “addHandler” call that’s producing the duplicated output. Is there a way to set the format of the root logger without this duplication? Thanks!

  • 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-12T18:55:32+00:00Added an answer on May 12, 2026 at 6:55 pm

    except: without exception class[es] is a good way to get in trouble. I believe logging module in Python 2.3 has basicConfig() function, but with less options. Since it accepts **kwargs it may fail at any moment after doing some job. I think it already installed a handler with default format then failed to configure something. After catching exception you have installed another handler. Having 2 handlers you get 2 messages for each event. The simplest way in your case: avoid using basicConfig() at all and configure logging manually. And never use except: if you don’t reraise or log caught exception.

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

Sidebar

Related Questions

I'm learning Python and have been trying to understand more about the details of
I have project that creates dlls. These dlls are invoked from python later by
I have a class in my Python module that frobs widgets. It has several
I'm currently rewriting some python code to make it more efficient and I have
I've installed python 2.6 from source, and somehow later mistakenly installed another python 2.6
I am using python's very high level layer to embed some python code to
Python 3 really complicated the whole file reading process, when you have a binary
Python beginner here, I have a list of lists and want to refer to
I'd like convert strings to floats using Python 2.6 and later, but without silently
I have a python app in which I am creating packages in windows 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.