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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:24:37+00:00 2026-05-27T00:24:37+00:00

Was just looking at the logging docs in Python and came across funcName as

  • 0

Was just looking at the logging docs in Python and came across funcName as a parameter in the log formatter.

While it looks handy, great way to see exactly where the log is coming from obviously, someone’s raised a concern about it, possibly that it would need to generate a stack trace that would be a performance hit.

I assume it uses something like sys._getframe() and not the inspect module, which would have an impact in performance.

Is funcName something we could use in a production environment or should we stay away?

  • 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-27T00:24:38+00:00Added an answer on May 27, 2026 at 12:24 am

    Resist the temptation to guess, the source for logging is available to you as part of your Python distribution.

    How it finds the function name (logging/__init__.py):

    #
    # _srcfile is used when walking the stack to check when we've got the first
    # caller stack frame.
    #
    if hasattr(sys, 'frozen'): #support for py2exe
        _srcfile = "logging%s__init__%s" % (os.sep, __file__[-4:])
    elif __file__[-4:].lower() in ['.pyc', '.pyo']:
        _srcfile = __file__[:-4] + '.py'
    else:
        _srcfile = __file__
    _srcfile = os.path.normcase(_srcfile)
    
    # next bit filched from 1.5.2's inspect.py
    def currentframe():
        """Return the frame object for the caller's stack frame."""
        try:
            raise Exception
        except:
            return sys.exc_info()[2].tb_frame.f_back
    
    if hasattr(sys, '_getframe'): currentframe = lambda: sys._getframe(3)
    # done filching
    

    and then later:

    def findCaller(self):
        """
        Find the stack frame of the caller so that we can note the source
        file name, line number and function name.
        """
        f = currentframe()
        #On some versions of IronPython, currentframe() returns None if
        #IronPython isn't run with -X:Frames.
        if f is not None:
            f = f.f_back
        rv = "(unknown file)", 0, "(unknown function)"
        while hasattr(f, "f_code"):
            co = f.f_code
            filename = os.path.normcase(co.co_filename)
            if filename == _srcfile:
                f = f.f_back
                continue
            rv = (filename, f.f_lineno, co.co_name)
            break
        return rv
    

    also, no need to worry about the overhead: it figures out the function name before it works out whether or not you needed it so you might as well use it.

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

Sidebar

Related Questions

Just looking at ways of getting named constants in python. class constant_list: (A_CONSTANT, B_CONSTANT,
Just looking for the first step basic solution here that keeps the honest people
Just looking for the relevant documentation. An example is not necessary, but would be
Just looking at: (Source: https://xkcd.com/327/ ) What does this SQL do: Robert'); DROP TABLE
Just looking for a good PHP Image Library, I want to display images with
Just looking on resources that break down how frames per second work. I know
Basically just looking to see if you can capture an image from the webcam
I was just looking through some information about Google's protocol buffers data interchange format.
I'm just looking for a simple, concise explanation of the difference between these two.
I am just looking at the using statement, I have always known what it

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.