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#includeusing using //日志封装#define#define#define#define#define//class{public: // bool // static staticprivate: 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&{ staticlog; return;}bool{ int"LOG_LEVEL", /* SharedAppenderPtrnew _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 4665】 4665: 小w的喜糖 (DP+容斥)
4665: 小w的喜糖 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 94 Solved: 53 Description 废话不多说,反正小w要发喜 ...
- android intent 传递 二进制数据
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 实现序列化.
- 「学习笔记」wqs二分/dp凸优化
[学习笔记]wqs二分/DP凸优化 从一个经典问题谈起: 有一个长度为 \(n\) 的序列 \(a\),要求找出恰好 \(k\) 个不相交的连续子序列,使得这 \(k\) 个序列的和最大 \(1 \l ...
- python开发_tkinter
Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.Tk和Tkinter可以在大多数的Unix平台下使用, 同样可以应用在Windows和Macint ...
- leetcode644. Maximum Average Subarray II
leetcode644. Maximum Average Subarray II 题意: 给定由n个整数组成的数组,找到长度大于或等于k的连续子阵列,其具有最大平均值.您需要输出最大平均值. 思路: ...
- maven构建jar包
1.执行可执行的class,代码内需要有入口main方法 2.通过mvn package来构建jar包 3.使用java -jar test.jar来执行jar包 https://www.cnblog ...
- WM-G-MR-09模块
WM-G-MR-09模块,该模块同时支持SDIO与SPI 模式 USI(环隆电气)WM-G-MR-09,该WiFi芯片支持802.11b/g无线网络模式,芯片体积8.2×8.4×1.35(mm),采用 ...
- obd2 J1962M to DB9
- 创建Windows窗体 : WinMain() 与 WndProc()
#include <windows.h> #include <mmsystem.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, ...
- 【前台】【单页跳转】整个项目实现单页面跳转,抛弃iframe
即如下: [想做到点击nav侧边栏,仅替换右边div中的内容,而不是跳转到新的页面,这样的话,其实整个项目中就只有一个完整的页面,其他的页面均只写<body>内的部分即可,或者仅仅写要替换 ...