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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:53:43+00:00 2026-06-13T04:53:43+00:00

For the Log purpose, I want to know the name of method at runtime.

  • 0

For the Log purpose, I want to know the name of method at runtime.

Ex.

public void methodA(){
Log.e("INSIDE", "//some code here to get the name of methodA");
}

If I will get the name of method at runtime, it will reduce my repetitive task of inserting same log in different methods.

  • 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-13T04:53:44+00:00Added an answer on June 13, 2026 at 4:53 am

    I assume this is Java… If that is the case, this returns the name of the method you are currently in.

    String methodName = new Exception().getStackTrace()[0].getMethodName()
    

    Be careful though, don’t put this in a method, because then that will return the name of that method. You could also use this:

    public String getMethodName() {
        return new Exception().getStackTrace()[1].getMethodName();
    }
    

    This observes the second element of the stack trace, returning the correct method name.

    UPDATE:

    Though the first does what it takes, this is nicer: doesn’t involve creating a new object at least:

    Thread.currentThread.getStackTrace()[1].getMethodName();
    

    Warning I have to mention that all this however has an adverse impact on performance…

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

Sidebar

Related Questions

I've got following (simplified for example purpose) code and it works: void log(const string
I have the following code produce [AM123,DR2,F,99] from the console.log. Now I want to
For debugging purposes, I would like my app to log to a java.util.logging.SocketHandler. Here's,
LOG: Runtime Installer begin with version 3.3.0.3650 on Mac OS 10.7.4 x86 Commandline is:
I log traffic coming in to my site. I get a user's landing page
I am writing some small program in C--some log in, log out, create account,
I am working on an SMS Sending application and for login purpose i want
I am new to CDC and want to know if there is any problem
I have a regular C# code. I have no exceptions . I want to
My company is considering using flume for some fairly high volume log processing. We

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.