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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:04:08+00:00 2026-06-12T02:04:08+00:00

I found similar questions here, but my question is bit different… I have log()

  • 0

I found similar questions here, but my question is bit different…
I have log() function as staticmethod in MyUtil class:

class MyUtil(object):

    @staticmethod
    def log(message, level):
    ...

but now I have to know from which class/object this staticmethod was called?
For example:

class Deployer(object):

    def deploy(self):
        ...
        MyUtil.log ("Starting deployment", "info")
        ...

Is it possible to get and log this “Deployer” class name from MyUtil.log function?

(I’m aware that this is very un-OO and probably never useful in a well written program, but anyway…)

  • 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-12T02:04:09+00:00Added an answer on June 12, 2026 at 2:04 am

    It’s not the nicest design, logging is a “singleton” with all of its drawbacks, but if you are willing to accept that, there’s some language support for your problem. You can get the caller by inspecting the stack:

    import inspect
    
    class MyUtil(object):
        @staticmethod
        def log(message, level):
            frame, module, line, function, context, index = inspect.stack()[1]
            self_name = frame.f_code.co_varnames[0]  # Name of the first argument (usually 'self')
            instance = frame.f_locals[self_name]
            class_name = instance.__class__.__name__
            print class_name
    
    class Deployer(object):
        def deploy(self):
            MyUtil.log ("Starting deployment", "info")
    
    Deployer().deploy()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen similar questions on here but haven't found an answer. I'm taking
For the record: I found a similar question here but I have to elaborate
I can't resolve this issue, I found a similar question here but: setting the
I've looked at similar questions here but I haven't found one particular to my
I've found a similar question here , but I'm looking for more general solutions.
I found this similar question here , but this is really old. Was it
I found a few questions similar to this one here on SO, but none
I found similar questions asked here but there weren't answers to my satisfaction. So
Found a couple of similar questions here on this, but couldn't figure out how
Found a couple of similar questions here on this, but couldn't figure out how

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.