log4cpp windows下运用(3)----log4cpp 使用需注意的点

1   rollingpolicy_type_sizewin下:  如果记录(磁盘储存文件)正在进行,打开其中任一文档,当写文档达到最大限定值时,会将当前写的文档清空,从 0字节开始再写。

2  log4crc设置的路径应存在,若不存在,将不会为其新建路径/文件夹。

3  log4crc的路径问题没有处理好

4  经过查看源代码, VERSION应和log4crc中version保持一致,所以在defs.h中添加宏VERSION为版本号字符串

5  将SD_DEBUG 和 SD_ERROR设置为1时可以查看log4c内部运行记录信息

6  appender_type_rollingfile粘贴时是线程安全的。

7 线程不安全的原始解释:
l og4c _i ni t ( ) This function must be called successfully just once by the application. If two
threads call this at the same time the behavior is undefined. The problem is that both threads
will start to initialize global objects and the behavior is this case is undefined.
l og4c _f i ni ( ) The same is true of l og4c _f i ni ( ) this function can safely be called by only one
thread at a time. Furthermore when you call l og4c _f i ni ( ) you must be sure that there are no
calls to the logging API in flight if there are then l og4c _f i ni ( ) goes ahead freeing up Log4C
objects (like categories, appenders and layouts) so this will probably crash your application.
Readonly type Log4C calls like l og4c _c a t e gor y_i s _pr i or i t y_e na bl e d( ) and so on are MT safe
between themselves and calls to logging functions like l og4c _c a t e gor y_l og( ) but are not MT
safe with respect to l og4c _i ni t ( ) and l og4c _f i ni ( ) .
Issues related to lazy creation and intialization of objects.
Lookup and creation type calls like l og4c _c a t e gor y_ge t ( ) , l og4c _a ppe nde r _ge t ( ) ,
l og4c _l a yout _ge t ( ) and so on are not MT safe, even between themselves. The problem
is that if two threads call l og4c _c a t e gor y_ge t ( ) at the same time then, if the category
instances do not yet exist in the internal store of category instances, then the threads
may clash as they write to the shared hash that stores the instance references. This is
because no synchronization is provided on the shared instance hash.
Calls to l og4c _c a t e gor y_l og( ) are not MT safe when called on the same categories. The
problem is that log4c_category_log() eventually calls l og4c _a ppe nde r _a ppe nd( ) to log
the message. However, if the appender has not already been opened then it calls
l og4c _a ppe nde r _ope n( ) , which is not MT safe. The result could be that the two threads
will to open the appender at the same time which will give rise to undefined behavior.


8 通过提供一个打开所有open函数的接口,供调用者在程序初始化时调用(多线程开始前)。采用rollingplicy,第七点的l og4c _c a t e gor y_l og( ) 
的多线程安全问题可通过把rollingfile_open放在上述的接口中,先期调用即可解决此多线程问题。其他appender都是使用局部变量,不会影响多线程安全。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值