简体   繁体   English

Log4cplus:在gcc 4.8.5的过滤器中集成正则表达式

[英]Log4cplus: integrate regular expression in filters on gcc 4.8.5

Log4cplus has the spi::StringMatchFilter filter, which enables a simple matching of a string or sub-string to the log message (event message). Log4cplus具有spi :: StringMatchFilter过滤器,该过滤器使字符串或子字符串与日志消息(事件消息)的简单匹配成为可能。

I have gcc version 4.8.5 and what I would like to do is add to the Log4cplus the ability for filtering log messages using regular-expression and not just a simple sub-string (simple strstr search). 我有gcc版本4.8.5,我想做的就是向Log4cplus添加使用正则表达式过滤日志消息的功能,而不仅仅是简单的子字符串(简单的strstr搜索)。

I have tried using the std::regex and std::tr1::regex libs, but unfortunately their functions are not fully implemented on gcc 4.8 compilers. 我尝试使用std :: regex和std :: tr1 :: regex库,但是不幸的是,它们的功能在gcc 4.8编译器上并未完全实现。

I would be glad to get a direction or an idea of how I can achieve my goal? 我将很高兴获得如何实现目标的方向或想法? (I cannot upgrade my gcc, nor use boost libs). (我不能升级我的gcc,也不能使用boost库)。

I know one option is to use the PCRE lib by compiling the Log4cplus Makefile with this lib and add the regular-expression functions in the Log4cplus Filter.cxx src code, but I am not sure of how to modify the Log4cplus Makefile to link to the PCRE lib (where and how to add the PCRE lib link). 我知道一种选择是通过使用该库编译Log4cplus Makefile来使用PCRE库,并在Log4cplus Filter.cxx src代码中添加正则表达式函数,但是我不确定如何修改Log4cplus Makefile以链接到PCRE库(在何处以及如何添加PCRE库链接)。

I would be grateful for any suggestion. 如有任何建议,我将不胜感激。

I think this is bit too broad a question. 我认为这是一个太宽泛的问题。

You do not need to modify log4cplus itself. 您不需要修改log4cplus本身。 You can put the filter into your own application code and register the filter with factory registry: 您可以将过滤器放入自己的应用程序代码中,并在工厂注册表中注册过滤器:

#include <log4cplus/spi/factory.h>

// Into main() or some other convenient place:

log4cplus::spi::FilterFactoryRegistry& filter_reg = log4cplus::spi::getFilterFactoryRegistry();

LOG4CPLUS_REG_PRODUCT (filter_reg, "your::ns::", YourFilterClassNameHereInYourNs, your::ns::, 
    log4cplus::spi::FilterFactory);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM