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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:18:54+00:00 2026-05-14T01:18:54+00:00

Do you know any easy way to find a logging call that throws not

  • 0

Do you know any easy way to find a logging call that throws “not enough argumenst for format string”.
On my workstation I’ve modified logging/__init__.py to print the msg so I can easily find the line in the source.

But do you have any idea what to do on the testing environment where you can’t change python standard library nor run pdb easily?

Note: The traceback is meaningless, and it is caugth by the logging library.
Here is an traceback:

  File "/usr/lib/python2.6/logging/handlers.py", line 71, in emit
    if self.shouldRollover(record):
  File "/usr/lib/python2.6/logging/handlers.py", line 144, in shouldRollover
    msg = "%s\n" % self.format(record)
  File "/usr/lib/python2.6/logging/__init__.py", line 648, in format
    return fmt.format(record)
  File "/usr/lib/python2.6/logging/__init__.py", line 436, in format
    record.message = record.getMessage()
  File "/usr/lib/python2.6/logging/__init__.py", line 306, in getMessage
    msg = msg % self.args
TypeError: not enough arguments for format string

And here is the code in standard library that catch the error

    try:
        if self.shouldRollover(record):
            self.doRollover()
        logging.FileHandler.emit(self, record)
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        self.handleError(record)

Solution as suggested by Alex:
I’ve wrapped the getMessage to print the msg and args. Here is the code:

def print_log_record_on_error(func):
    def wrap(self, *args, **kwargs):
        try:
            return func(self, *args, **kwargs)
        except:
            import sys
            print >>sys.stderr, "Unable to create log message msg=%r, args=%r " % (
                                getattr(self, 'msg', '?'), getattr(self, 'args', '?'))
            raise
    return wrap
import logging
logging.LogRecord.getMessage = print_log_record_on_error(logging.LogRecord.getMessage)
  • 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-14T01:18:55+00:00Added an answer on May 14, 2026 at 1:18 am

    Generally, the best way to catch an exception (including the one you mention) is to put the suspect code in the try clause of a try/except statement; in the except clause you can use the traceback module or other ways to pinpoint the errant statement.

    Otherwise-uncaught exceptions end up in sys.excepthook, which is another way you can use to get a traceback if needed.

    However, I don’t think the logging module has an architected way to tell it “let exceptions propagate” — in which case your best bet, dirty as it may be, is probably monkey-patching. In other words, you generally can “change the Python standard library” at runtime — by setting identifiers therein to your own functions / classes / etc wrapping the standard ones. For example, if you know the problem is with a logging.warning call, a “proof of concept” monkeypatch might be:

    import logging, traceback
    
    orgwarn = logging.warning
    def mywarn(msg, *a):
      try: res = msg % a
      except TypeError:
        traceback.print_exc()
      return orgwarn(msg, *a)
    logging.warning = mywarn
    

    There are cleaner ways, but they may be somewhat cumbersome (e.g., make your own logger class and set it as the root logger). Monkey-patching is not a good way to operate in a production environment (it’s fragile to system upgrades, can be hard to understand and maintain, etc), but it can be acceptable for debugging and testing purposes.

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

Sidebar

Related Questions

Do any of you know of an easy/clean way to find a substring within
Anyone know if any easy way to find out if a site is written
I would like to know if there is any easy way to rank blog
Is there any easy way to find min/max value in the set of input
Is there any easy way to convert a URL that contains to two-byte characters
Do you know any way for safe copy cut operation in Android? I want
Do you know any library that will help doing that? I would write a
Do you know any blueprints for organizing a WCF application in a way similar
Do you know any controls inherited from the ItemsControl that have horizontal orientation of
Simple question. Does anyone know an easy way to convert SpreadsheetML (Excel 2003 XML)

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.