初学者:如何使用Pantheios记录API库替换#ifdef DEBUG?如何解决SEVLEVEL? [英] Beginner: How to use the Pantheios logging API library as a replacement for #ifdef DEBUG? How to def SEVLEVEL?

查看:199
本文介绍了初学者:如何使用Pantheios记录API库替换#ifdef DEBUG?如何解决SEVLEVEL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在动态搜索算法中记录很多事件(例如关于收敛到全局最优的信息)。此日志记录应该有一个开关,以关闭/打开。现在有很多可能性来实现:




  • 实现算法的日志版本和非日志版本 - >冗余

  • 使用宏 - >丑陋并不安全

  • 使用c ++日志库(或:使用日志功能范围的1%
  • 我决定使用 Pantheios ,尤其是因为效果声明想要失去多少性能,因为这种日志记录,这只是在开发中需要)。我不得不承认,我不需要这个库的很多功能,但我认为我会是一个更好的/更安全的方式使用它。也许会有一个更好的选择我不知道(我需要编译时决定只有日志 - >不知道是否有为此目的设计的日志库)。



    在编译,安装和最终链接之后(使用手动链接,但使用 scons 构建工具;使用gcc - >显式链接),我想尝试一个例子。



    让我们将其减少为以下内容:

      includepantheios / pantheios.hpp
    #includepantheios / frontends / stock.h
    const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY [] =pantheios_test; //指定进程标识

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

    链接是使用以下文件完成的:



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



    现在的简单问题是:如何关闭/打开控制台输出?如何选择向后端提供的严重性级别?



    查看文档可以了解很多具有严重性的函数级别,但这些函数会自动调用一次以进行初始化。我知道严重程度的动态变化是可能的。我不知道,我在哪里更改这些设置。他们应该在前端组件我想。链接到fe_all已经是某种级别被记录的决策,而不是级别不是?



    这应该是相对容易的,因为在我的情况下,

    感谢您的帮助。



    Sascha

    解决方案


    链接到fe_all已经是某种级别被记录的决定?


    简短回答:是。



    fe.all启用所有严重性level:allmeesages are logged。



    如果您想要更好的控制,请尝试fe.simple。默认情况下,它会打开调试版本中的所有内容,除了DEBUG和INFO之外的所有内容。您可以通过调用fe.simple头(即pantheios / frontends / fe.simple.h,iirc)中的函数pantheios_fe_simple_setSeverityThresdhold()(或类似的东西)来随时更改阈值 - 调试或释放。



    请注意,Pantheios被称为记录 API 库。我想的意图是,它提供了一个API,初始化控制和输出现有的丰富日志记录库。它提供股票前端和后端是为用户方便(i)快速上手速度,和(ii)简单的要求(您的程序可能符合资格)。



    btw,我认为项目网站上的Pantheios论坛得到了很好的支持,因此可能想在这里以及这里提出问题。


    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

    解决方案

    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.

    这篇关于初学者:如何使用Pantheios记录API库替换#ifdef DEBUG?如何解决SEVLEVEL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆