title: Error Logging C++ Preprocessor Macros __LINE__, __FUNCTION__
body: <p>I trying to incorporate a simple error logging into my existing app, at the moment it reports errors just using <code>cout</code> so I was hoping to keep a similar interface using the <code>&lt;&lt;</code> operator. However I want it to log the line and function the error occurred, but I don't want to have to type <code>__LINE__, __FUNCTION__</code> every time I need to log. Does anyone know a trick I can use to allow the <code>__LINE__</code> macro to be used inside another function, reporting the calling line instead? Hope that makes sense.</p>
  
  <pre><code>class myLogClass {
      uint8_t level;                  
  public:                 
      bool operator&lt;&lt;( const char * input );          
  };
  
  bool myLogClass::operator&lt;&lt;( const char * input ) {
      logItInSQL( input );
      return true;
  }
  </code></pre>
  
  <p>Instead of this every time</p>
  
  <pre><code>myLogClass &lt;&lt; "Line No: " &lt;&lt; __LINE__
      &lt;&lt; " Function: " &lt;&lt; __FUNCTION__
      &lt;&lt; " Error: " &lt;&lt; "This is my error to be logged";
  </code></pre>
  
  <p>I would like to just be able to do:</p>
  
  <pre><code>myLogClass &lt;&lt; "This is my error to be logged";
  
  bool myLogClass::operator&lt;&lt;( const char * input ) {
      logItInSQL( " Line No: __LINE__" );
      logItInSQL( " Function: __FUNCTION__" );
      logItInSQL( " Error: " + input );
      return true;
  }
  </code></pre>