log4cplus的安装与使用初步
1. 简单介绍
log4cplus是C++编写的开源的日志系统,The
purpose of this project is to port the excellentLog
for Java (log4j)logging library to C++。
log4cplus具有灵活、强大、使用简单、多线程安全的特点,实在是杂牌军、游击队的福音。
2. 安装使用(Linux)
log4cplus安装使用很easy。从其官网:http://log4cplus.sourceforge.net/ 下载最新版本号
执行:
tar xvzf log4cplus-x.x.x.tar.gz
cd log4cplus-x.x.x
./configure --prefix=/where/to/install
make
make install
在安装文件夹下生成include和lib两个文件夹。分别为头文件和库文件
使用:
g++ -o server /mnt/hgfs/work_vm/project/work_project/server/obj/main.o
-L../..//third/log4cplus/lib/ -L../..//third/boost/lib/-llog4cplus
-lpthread -I/mnt/hgfs/work_vm/project/work_project/server/include -I../..//third/log4cplus/include/-I../..//third/boost/include/
编译參数:
-L../..//third/log4cplus/lib/
-llog4cplus
-lpthread
-I../..//third/log4cplus/include/
3. 使用
log4cplus主要包含layout、appender、loglevel等内容。能够參考:
http://masterdog.bokee.com/153892.html
写的很nice
4. 包装
logcplus包装下用起来很方便,下面是我的包装。供參考
Log.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// // ////////////////////////////////////////////////////////////////////// #if #define #include #include #include #include #include #include #include #include #include #include using
using
//日志封装 #define #define #define #define #define // class
{ public : // bool
// static
static
private : Log(); virtual
//log文件路径及名称 char
char
}; #endif |
Log.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// // ////////////////////////////////////////////////////////////////////// #include ////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////// Logger "main_log" ); Log::Log() { snprintf(_log_path, sizeof (_log_path), "%s" , "../log" ); snprintf(_log_name, sizeof (_log_name), "%s/%s.%s" , "log" ); } Log::~Log() { } Log& { static
log ; return
; } bool
{ int
"LOG_LEVEL" , /* SharedAppenderPtr new
_append->setName( "file ); /* std::string "[%p] ; std::auto_ptr<Layout> new
/* _append->setLayout(_layout); /* /* Log::_logger.addAppender(_append); /* Log::_logger.setLogLevel(Log_level); return
; } |
int Log_level = Main_config::instance().get_config().Read("LOG_LEVEL", 0);
Main_config是我自己包装的一个配置类(參考:http://blog.csdn.net/yfkiss/article/details/6802451)。通过读取配置设置log level。
使用:
#inlucde "Log.h"
程序初始化的时候:
// 打开日志
if (!Log::instance().open_log())
{
std::cout << "Log::open_log() failed" << std::endl;
return false;
}
然后使用NOTICE、FATAL等就能够打印日志到文件。
1
2
3
4
5
6
7
8
9
10
11
|
#include .... // if
{ std::cout "Log::open_log()
return
; } ..... NOTICE( "Server ); FATAL( "Server ); |
转自:http://blog.csdn.net/yfkiss/article/details/6802422
log4cplus的安装与使用初步的更多相关文章
- php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中
php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中 1.phalcon框架的安装: phalcon框架在windows本地安装可以利用wamp软件,安装之后可以查看对应 ...
- Microsoft Visual Studio 2010下log4cplus的安装,集成,测试
原文:http://blog.csdn.net/eclipser1987/article/details/6904301 log4cplus是C++编写的开源的日志系统,功能非常全面,用到自己开发的工 ...
- drf安装与APIView初步分析
drf安装 1. pip install djangorestframework 2. 在settings文件中注册app : INSTALLED_APPS = [..., 'rest_framewo ...
- windows环境安装haproxy及初步配置负载均衡使用示例
安装HaProxy 首先需要下载windows环境下需要文件,这里下载的是一个别人编译好的一个文件,这里省去了编译的过程,使用的版本是haproxy-1.7.8. 下载后直接解压到对应的目录下.示例( ...
- node安装 教程 + git初步
我的系统是win8.1 64位 这个是对应的安装包:http://files.cnblogs.com/files/zxyun/node-v0.12.5-x64.zip 安装中有不懂可以参考下面的两 ...
- linux下安装nginx及初步认识
linux下安装配置nginx nginx:是一个高性能的反向代理服务器正向代理代理的是客户端,反向代理代理的是服务端. 这里以nginx-1.12.2版本为例子 1.首先去官网下载nginx-1.1 ...
- 全网最详细的Windows系统里Oracle 11g R2 Client客户端(64bit)安装后的初步使用(图文详解)
不多说,直接上干货! 前期博客 全网最详细的Windows系统里Oracle 11g R2 Client(64bit)的下载与安装(图文详解) 命令行方式测试安装是否成功 1) 打开服务(cmd— ...
- 全网最详细的Windows系统里Oracle 11g R2 Database(64bit)安装后的初步使用(图文详解)
不多说,直接上干货! 前期博客 全网最详细的Windows系统里Oracle 11g R2 Database(64bit)的下载与安装(图文详解) 命令行方式测试安装是否成功 1) 打开服务(cm ...
- 前端新手如何安装webstorm ,初步搭建react项目
下载安装webstorm:配置成功: 配置成功后就可以开启webstorm项目了.(存微信收藏..) 1:在webstorm下配置node环境: 2:完成之后: React官方脚手架地址: https ...
随机推荐
- 【BZOJ】4709: [Jsoi2011]柠檬
4709: [Jsoi2011]柠檬 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 779 Solved: 310[Submit][Status][ ...
- [转]android中OnTouch和OnClick、 imagebutton的src和background有什么区别
1.OnTouch和OnClick有何区别? 专业回答 1.onClick就传入一个View对象,而 onTouch要传入一个View 对象和 MotionEvent的对象2.onTouch对控件 ...
- 稀疏编码直方图----一种超越HOG的轮廓特征
该论文是一篇来自CMU 的CVPR2013文章,提出了一种基于稀疏编码的轮廓特征,简称HSC(Histogram of Sparse Code),并在目标检测中全面超越了HOG(Histogram o ...
- pt-archive提速的实践经验
最近遇到很多业务需求,需要进行数据导出工作,由于有格式要求,故之前一直使用mysqldump的方法. mysqldump -uuser -ppassword -S mysql.sock -t db t ...
- mysql 绿色版安装
1. 下载MySql5.6.10GA解压缩版,这就不多说也不上图了,下不到或者下好之后不知道如何解压的接下去的文章也没什么好多看的. 2. 解压好之后进入根目录是这样个情况(本人使用的是MySql5. ...
- Inrush limiter also provides short-circuit protection
For containing large amounts of bulk capacitance, controlling inrush currents poses problems. The si ...
- HC-07 蓝牙串口模块
http://www.wavesen.com/probig.asp?id=17 本模块为新推出的产品,各项功能和性能.及引脚封装,均兼容于HC-06. 为低成本需求的的客户推荐本产品.相比HC-06来 ...
- Using TXMLDocument, Working with XML Nodes
Using TXMLDocument The starting point for working with an XML document is the Xml.XMLDoc.TXMLDocumen ...
- vsftpd FTP服务器配置
步骤如下: 0. 进入目录/etc/vsftpd,将vsftpd.conf备份为vsftpd.conf.bak(否则启动时会启动这个)1. 进入目录/etc/vsftpd,创建文件myserver.c ...
- Git本地仓库与Github远程仓库关联
如果你已经在本地创建了一个Git仓库,又想在GitHub创建一个Git仓库,并且让这两个仓库进行远程同步,那就需要用到SSH Key,github拿到了你的公钥就会知道内容是你推送的. SSH Key ...