How to include the calling class and line number in the log using Pantheios?

I just started using Pantheios and it really looks like a great library to register with! Maybe even the best for C ++! Congratulations to the author!

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

I use be.file as the end, and I defined the user interface by looking at the fe.simple example. Is this somehow related to PANTHEIOS_EXTERN_C const char PANTHEIOS_FE_PROCESS_IDENTITY[] , or am I mistaken?

+4
source share
2 answers

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

 #include <pantheios/pantheios.hpp> #include <pantheios/frontends/fe.Nh> //#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 happens here is that you must override PANTHEIOS_TRACE_PREFIX before you include trace.h, as I showed above. Other lines of code are included simply to show you where #define is. And sorry for the late reply. If you want, I can publish the download on my blog using a fixed-content DLL project that anyone can use in their solution for simple file-based logging. Leave a comment if you have interest in this project.

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

Q9: "Does Pantheios provide a configuration that gives a registered message containing a containing function equivalent to:

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

without having to write this (or some kind of shell that checks for compiler support). "[March 15, 2008]

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

To enable this function, let's say you want it to have the format <file>(<line>): <func>: To do this, you define it as follows:

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

Please note that a determination must be made before including pantheios / trace.h. Therefore, a safer way to do 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> 
+5
source

I did not find a way to include this information automatically - you can, of course, add a line number to the log message itself if you use the __LINE__ macro. Not sure how portable this is.

0
source

Source: https://habr.com/ru/post/1302513/


All Articles