3

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:

  • implement a log-version and a non-log-version of the algorithm -> redundancy
  • use macros -> ugly and not that safe
  • use a c++ logging library (or: use 1% of the functional range of a logging library).

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

sascha
  • 32,238
  • 6
  • 68
  • 110

1 Answers1

7

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.

dcw
  • 3,481
  • 2
  • 22
  • 30
  • 1
    I did look into it with the things you mentioned and i was able to control the log-severity with "PANTHEIOS_CALL(int) pantheios_fe_simple_setSeverityCeiling(int ceiling);" (defined in fe.simple.h; like you mentioned). Thank you for your help. Maybe one little question more: you mentioned some kind of compile-time severity-choosing trough release/debug-mode. I know these modes from the intel and visual studio compiler. But is there some kind of equivalent in gcc (i suppose the optimization flags -O0 and -O1..-O3 doens't work for that)? Just out of curiosity. – sascha Nov 26 '10 at 16:08
  • 3
    IIRC, the Pantheios libs for all compilers/platforms come in debug and release builds. So I would think that if you link to fe.simple's debug lib you'll get all severities on by default, and if you like to its release lib you'll get all severities except DEBUG/INFO by default. Is that what you mean? Not sure how that's done in scons; you'll have to ask on the Pantheios forums for that kind of build stuff. HTH – dcw Nov 26 '10 at 19:07