• Articles
  • An open source C++ lightweight & cross p
Published by
Apr 4, 2014 (last update: Apr 4, 2014)

An open source C++ lightweight & cross platform log library: Log4z

Score: 3.7/5 (45 votes)
*****

Introduction:

Log4z is an open source C++ lightweight & cross platform log library.
It provides in a C++ application log and trace debug function for 7*24h service program.

Support 64/32 of debian, redhat, centos, suse, windows.


Feature:

MIT open source license,very liberal.

Cross Platform Linux & Windows, Lightweight only one cpp sourse file one header file.

Multi-Logger Output, Rolling File, Priority Filter, Thread Safe.

Screen Display Log with Different Color.

Support format-style and stream-style write log.

Support configure from file and hot update, or can direct fast work without any config.


File Name Format:

LogName_YearMonthDayHourMinute_ProcessID_BlockNumber.log


E:\GITHUB\LOG4Z\PROJECT\BIN
│──advanced_test.exe
│──config.cfg
│──fast_test.exe
│──stress_test.exe
│
├─AdvacedLog
│──│───FileConfig_2013100921_003852_000.log
│──│───FileConfig_2013101313_005920_000.log
│
├─log
│──│──advanced_test_2013100921_003852_000.log
│──│──advanced_test_2013101313_005920_000.log
│──│──fast_test_2013100921_003855_000.log
│──│──fast_test_2013101313_006160_000.log
│──│──stress_test_2013101313_007196_000.log
│──│
│──└─2013_10
│─────│────Dynamic_2013100921_003852_000.log
│─────│────Dynamic_2013101313_005920_000.log
│
└─Stress
───│────NetWork_2013101313_007196_000.log
───│────NetWork_2013101313_007196_001.log
───│────NetWork_2013101313_007196_002.log
───│────NetWork_2013101313_007196_003.log
───│────NetWork_2013101313_007196_004.log

[Log Content]



How To Use Log4z example 1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "../log4z.h"
#include <iostream>
#include <stdio.h>
#include <stdarg.h>
using namespace zsummer::log4z;

#ifdef WIN32
#include <windows.h>
#endif
int main(int argc, char *argv[])
{

	//start log4z
	ILog4zManager::GetInstance()->Start();

	LOGI("begin test stream log input....");
	LOGD("stream input *** " << "LOGD LOGD LOGD LOGD" << " *** ");

	LOGFMTI("begin test format log input....");
	LOGFMTD("format input *** %s *** %d ***", "LOGFMTD", 123456);
	LOGA("main quit ...");
	return 0;
}


How To Use Log4z example 2:

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "../log4z.h"
#include <iostream>
#include <stdio.h>
#include <stdarg.h>
using namespace zsummer::log4z;

#ifdef WIN32
#include <windows.h>
#endif
int main(int argc, char *argv[])
{

	//start log4z
	ILog4zManager::GetInstance()->Start();

	//LOGD: LOG WITH level LOG_DEBUG
	//LOGI: LOG WITH level LOG_INFO
	//...
#ifdef WIN32
	LOGI("begin test stream log utf-16 string input....");
	WCHAR wChar[100] = L"check unicode log string";
	std::wstring wStr = L"check wstring log";
	LOGF(L"PATH=" << wChar << ":" << wStr);
#endif

	LOGI("begin test stream log input....");
	LOGD("stream input *** " << "LOGD LOGD LOGD LOGD" << " *** ");
	LOGI("stream input *** " << "LOGI LOGI LOGI LOGI" << " *** ");
	LOGW("stream input *** " << "LOGW LOGW LOGW LOGW" << " *** ");
	LOGE("stream input *** " << "LOGE LOGE LOGE LOGE" << " *** ");
	LOGA("stream input *** " << "LOGA LOGA LOGA LOGA" << " *** ");
	LOGF("stream input *** " << "LOGF LOGF LOGF LOGF" << " *** ");


	LOGI("begin test stream log all types input....");
	LOGD("char:" <<'c'
		<< ", unsigned char:" << (unsigned char) 'c'
		<< ", short:" << (short) -1
		<< ", unsigned short:" << (unsigned short) -1
		<< ", int:" << (int) -1
		<< ", unsigned int:" << (unsigned int) -1
		<< ", long:" << (long) -1
		<< ", unsigned long:" << (unsigned long) -1
		<< ", long long:" << (long long) -1
		<< ", unsigned long long:" << (unsigned long long) -1
		<< ", float:" << (float) -1.234567
		<< ", double:" << (double) -2.34566
		<< ", std::string:" << std::string("fffff")
		<< ", int *:" << ( int *) argv
		<< ", const int *:" << (const int *) argv
		<< ", constant:" << 1000 
		<< ", constant:" << 100.12345678
		<< ", bool:" << true
		<< ", show hex data:" << BinaryBlock("1234567890abcdefghigklmnopqrstuvwxyz_zyw_zsummer_log4z", 50));


	std::string str;
	str.resize(3000, 's');


	// cannot support VC6 or VS2003
	LOGFMTI("begin test format log big string more than buff size input....");
	LOGFMTI("begin test format log input....");
	LOGFMTD("format input *** %s *** %d ***", "LOGFMTD", 123456);
	LOGFMTI("format input *** %s *** %d ***", "LOGFMTI", 123456);
	LOGFMTW("format input *** %s *** %d ***", "LOGFMTW", 123456);
	LOGFMTE("format input *** %s *** %d ***", "LOGFMTE", 123456);
	LOGFMTA("format input *** %s *** %d ***", "LOGFMTA", 123456);
	LOGFMTF("format input *** %s *** %d ***", "LOGFMTF", 123456);
	LOGFMT_DEBUG(LOG4Z_MAIN_LOGGER_ID, "%s", str.c_str());
	// end

	LOGI("begin test stream log big string more than buff size input....");
	LOGD(str);
	LOGA("main quit ...");
	return 0;
}



How to compile


Directly Using The Way :


Add files log4z.cpp log4z.h and compile together in the existing projects.

Make Library To Use


In Windows:
 
Open and compile log4z/vc2005/log4z.vcproj


In Linux :
1
2
3
cd log4z/g++
cmake .
make


Release Download Link: https://github.com/zsummer/log4z/releases

Attachments: [log4z-2.5.0.zip]