views:

156

answers:

2

I just started using Pantheios and it feels really like a great library for logging! Maybe even the greatest one for C++! Congratulations to the author!

However, I could not find neither in the documentation nor in all the forum posts anything about how to include the calling class and the line number in the log.

I'm using be.file as back end and I defined custom front end, looking at the example of fe.simple. Is this something to do with the PANTHEIOS_EXTERN_C const char PANTHEIOS_FE_PROCESS_IDENTITY[] or I'm on a completely wrong way?

A: 

I haven't found a way to include that information automatically - you can of course add the line number to the log message itself if you're using the __LINE__ macro. Not sure how portable this is, though.

Timo Geusch
+2  A: 

The answer for this actually is in the FAQ file included in the library download. I have a fixed-back-end DLL that has the following header in it and I am able to include the class, function and line number in the log file.

#include <pantheios/pantheios.hpp>
#include <pantheios/frontends/fe.N.h>
//#include <pantheios/frontends/fe.simple.h>
#ifndef PANTHEIOS_INCL_PANTHEIOS_H_TRACE
#define PANTHEIOS_TRACE_PREFIX         __FILE__ "(" PANTHEIOS_STRINGIZE(__LINE__) "): " __FUNCTION__ ": "
#endif /* PANTHEIOS_INCL_PANTHEIOS_H_TRACE */
#include <pantheios/trace.h>
#include <pantheios/inserters.hpp>
#include <pantheios/backends/bec.file.h>    // be.file header

What is happening here is that you have to redefine PANTHEIOS_TRACE_PREFIX before including trace.h, which is what I have shown above. The other lines of code are included simply to show you where the #define goes. And sorry for the delayed response. If you wish I could post a download on my blog with a fixed-back-end DLL project that anyone could use in their solution for simple file-based logging. Leave a comment if you have any interest in that project

Update 2/28/2010 12:53 AM CST: For your reference here is the question from the FAQ:

Q9: "Does Pantheios provide a configuration that yields a logged message containing the containing function, equivalent to:

   log(informational, __FUNCTION__, ": my message");

without having to write that (or some wrapper that checks for compiler support)." [15th March 2008]

A9: You need to #define PANTHEIOS_TRACE_PREFIX to what you want. By default it is __FILE__ "(" PANTHEIOS_STRINGIZE(__LINE__) "): ", which gives the format <file>(<line>):

To include the function, lets says you want it to have the format <file>(<line>): <func>:. To achieve this you'd define it as follows:

#include <pantheios/pantheios.h>
#define PANTHEIOS_TRACE_PREFIX         __FILE__ " " PANTHEIOS_STRINGIZE(__LINE__) ": " __FUNCTION__ ": "
#include <pantheios/trace.h>

Note that the definition must come before the inclusion of pantheios/trace.h. Therefore, a safer way of doing this is as follows:

/* File: myPantheiosRootHeader.h */
#include <pantheios/pantheios.h>

#ifdef PANTHEIOS_INCL_PANTHEIOS_H_TRACE
# error pantheios/trace.h must not be included before myPantheiosRootHeader.h
#endif /* PANTHEIOS_INCL_PANTHEIOS_H_TRACE */

#define PANTHEIOS_TRACE_PREFIX         __FILE__ " " PANTHEIOS_STRINGIZE(__LINE__) ": " __FUNCTION__ ": "
#include <pantheios/trace.h>
ossandcad
Thank you very much! I wonder how did I missed this in the FAQ... :)I also did everything in a DLL and it would be interesting to see how similar is it with your project.
m_pGladiator
Just one more comment: I was using methods instead of macros and the log always contained my wrapper method as caller. In order this to work, everything should be a macro.
m_pGladiator