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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:20:03+00:00 2026-05-11T08:20:03+00:00

I trying to incorporate a simple error logging into my existing app, at the

  • 0

I trying to incorporate a simple error logging into my existing app, at the moment it reports errors just using cout so I was hoping to keep a similar interface using the << operator. However I want it to log the line and function the error occurred, but I don’t want to have to type __LINE__, __FUNCTION__ every time I need to log. Does anyone know a trick I can use to allow the __LINE__ macro to be used inside another function, reporting the calling line instead? Hope that makes sense.

class myLogClass {     uint8_t level;                   public:                      bool operator<<( const char * input );           };  bool myLogClass::operator<<( const char * input ) {     logItInSQL( input );     return true; } 

Instead of this every time

myLogClass << 'Line No: ' << __LINE__     << ' Function: ' << __FUNCTION__     << ' Error: ' << 'This is my error to be logged'; 

I would like to just be able to do:

myLogClass << 'This is my error to be logged';  bool myLogClass::operator<<( const char * input ) {     logItInSQL( ' Line No: __LINE__' );     logItInSQL( ' Function: __FUNCTION__' );     logItInSQL( ' Error: ' + input );     return true; } 
  • 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. 2026-05-11T08:20:03+00:00Added an answer on May 11, 2026 at 8:20 am
    myLogClass << 'Line No: ' << __LINE__ ... 

    With your operator << chaining will not work since it returns a bool.

    bool myLogClass::operator << (const char * input) 

    It is customary to define stream insertion as follows:

    std::ostream& myLogClass::operator << (std::ostream& o, const char * input) {     // do something     return o; } 

    Do this:

    #define log(o, s) o << 'Line No: ' << __LINE__ << \                    ' Function: ' << __FUNCTION__ << \                    ' Error: ' << s // note I leave ; out 

    Additionally, you can wrap the macro in a do-while loop:

    #define log(o, s) do { o << 'Line No: ' << __LINE__ << \                    ' Function: ' << __FUNCTION__ << \                    ' Error: ' << s; \                    } while(0) // here, I leave ; out 

    Then you can happily write:

     myLogClass myLogger; // do this   // use it log(myLogger, 'This is my error to be logged'); // note the ; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just learning ASP.NET c# and trying to incorporate best practices into my
Hey everyone. I am trying to incorporate a simple UINavigationController into my tab bar
i am trying to incorporate iAd's into my app and in the process i'v
I'm trying to incorporate Devise and Cancan into a web app. I want users
I'm trying to incorporate some JavaScript unit testing into my automated build process. Currently
I am currently trying to incorporate Steve Sanderson's example code into my MVC 3
So, I'm trying to incorporate the libpthread.a library into my own library. But its
I have a rails app trying to incorporate some AJAX where clicking new opens
I am trying to incorporate prototype.js's bind() function into my Flash component. I found
I'm trying to incorporate user statistics into a site and decided to go for

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.