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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:22:10+00:00 2026-05-17T21:22:10+00:00

I have a logger class. Call it MyLogger . I may use it in

  • 0

I have a logger class. Call it MyLogger. I may use it in a function like this:

void MyFunc(MyLogger& oLogger)
{
   //Do stuff
   oLogger.Log("In MyFunc : Some Error");
   //Do something else
   oLogger.Log("In MyFunc : Some other error");
}

Now, I want to prepend "In MyFunc" to the logs if the log comes from inside MyFunc. Similarly for other functions…

Because this is tiresome, I tried something like this:

void MyLogger::PushPrependString(const char*)
{
   //Store prepend string in stack and set it as current prepend string.
}

void MyLogger::PopPrependString()
{
   //Pop the most recent prepend string.
}

Now, I can use these two functions like this:

void MyFunc(MyLogger& oLogger)
{
   oLogger.PushPrependString("In MyFunc : ");
   //Do stuff
   oLogger.Log("Some Error");
   //Do something else
   oLogger.Log("Some other error");
   oLogger.PopPrependString();
}

The trouble is, if there are multiple returns in a function, this becomes ugly. Is there any way around this? Is this a common problem? Is there any preprocessor macro like __FILE__ or __LINE__ for getting the name of the function a line appears in? Any comments would be appreciated. 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-17T21:22:11+00:00Added an answer on May 17, 2026 at 9:22 pm

    RAII – Resource Acquisition Is Initialization.

    In this case, you create an object on entry to the function that identifies the current function to the logging system; when the function exits (by any return or by exception thrown or by exception not caught), the object will be destroyed, and the destructor changes what is printed in future by the logging system.

    In C99, and maybe in some C++ compilers such as G++, there is a predefined variable, __func__ containing the function name. The C++ equivalent is more complex, I believe.

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

Sidebar

Related Questions

I have a generic Logger class that looks like this: class Logger { ...
the situation is like this: im creating a Logger class that can write to
I have a class Logger which, among other things has a method Log .
I have an issue here where I'm trying to call a class method on
I have some code in a thread. The code's main function is to call
I have a logger system which basically is a fancy way of writing my
We have lots of logging calls in our app. Our logger takes a System.Type
I was looking at the Ruby logging library Logging.logger method and have a question
I have a certain service where specific functions will take longer to call than
I am trying to enhance my Logger class with some conditionals to control what

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.