c++loggingpantheios

Beginner: How to use the Pantheios logging API library as a replacement for #ifdef DEBUG? How to def SEVLEVEL?


i want to log a lot of events in a dynamically search-algorithm (e.g. information about convergence to global optimum). This logging should have a switch to turn it off/on. Now there are a lot of possibilities to achieve that:

I decided to use Pantheios, especially because of the performance claims made (don't want to lose much performance because of this logging, which is only needed in development). I have to admit, that i don't need much of the functionality of this library, but i thought i would be a much nicer/safer way to use it. Maybe there would be a better suited alternative i don't know of (i need compile-time decisions only for logging -> don't know if there are logging-libraries designed for that purpose).

After compiling, installing and finally linking (no success with manually linking, but with the scons building tool; using gcc -> explicit linking), i wanted to try a little example.

Let's reduce that to something like the following:

#include "pantheios/pantheios.hpp"
#include "pantheios/frontends/stock.h"
const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = "pantheios_test";    // specify process identity

int main()
{
    pantheios::log_ALERT("alert-event");
    pantheios::log_DEBUG("debug-event");
    pantheios::log_INFORMATIONAL("just information");
    return 1;
}

Linking is done with the following files:

LIBS=['pantheios.1.core.gcc44', 'pantheios.1.be.fprintf.gcc44', 'pantheios.1.bec.fprintf.gcc44', 'pantheios.1.fe.all.gcc44', 'pantheios.1.util.gcc44']

The simple question is now: how to switch the console-output off/on? How to choose the severity-level which is given to the back-end?

Looking into the documentation lead me to a lot of functions which take a severity level, but these functions are automatically called once for initialization. I know that dynamic changes of severity-levels are possible. I don't know exactly, where i change these settings. They should be in the front-end component i think. Is linking to "fe_all" already some kind of decisions which level is logged ad which level isn't?

It should be relatively easy because in my case, i only need a compile-time decision about logging on/off.

Thanks for your help.

Sascha


Solution

  • Is linking to "fe_all" already some kind of decisions which level is logged ad which level isn't?

    Short answer: yes.

    fe.all enables all severity levels: "all" meesages are logged.

    If you want better control, try fe.simple. By default it switches on everything in debug builds and everything except DEBUG and INFO in release. You can change the threshold at anytime - in debug or release - by calling the function pantheios_fe_simple_setSeverityThresdhold() (or something similar) in the fe.simple header (which is pantheios/frontends/fe.simple.h, iirc).

    Be aware that Pantheios is described as a logging API library. I think the intention is that it provides an API, initialization control and output over an existing "rich" logging library. That it provides "stock" front-ends and back-ends is a convenience to users for (i) getting up to speed quickly, and (ii) simple requirements (for which your program may qualify).

    btw, I think the Pantheios forums on the project site are pretty well supported, so you may want to post questions there as well as here.