1 Star 0 Fork 47

jayfey/iLOG3

forked from calvinwilliams/iLOG3 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
README-EN 13.00 KB
一键复制 编辑 原始数据 按行查看 历史
calvinwilliams 提交于 2018-08-26 08:00 . ...
iLOG3 is a portable and easy to use, simple concept, high performance, multiple interfaces, native cross-platform, thread safety , following the LGPL source protocol , standard c log function library.
The basic features are as follows
* Native cross-platform, which means that your software on the log module is easily transplanted, currently supported WINDOWS & UNIX & Linux, iLOG3 will accordingly implementation and optimization on different operating systems
* Five log levels
* Variable parameter of the journal functions and macros
* Log style scheme selection
* Output media file, the standard output and standard error output, syslogd or WINDOWS EVENT, custom medium
Advanced features as follows
* Advanced log options
* According to turn archives by log file size, every day, every hour
* Support line logging style custom callback function, it is easy to customize your own line of log format
* Support of the log file open, output, close the custom callback function, it is easy to extend into the log output to a remote server
* Thread safety, simple MDC, based on the default thread local storage global logging handle
Layered implementation "LOG handle layer (LOG) - > LOG handle collection (LOGS) - > config file interface layer (LOGCONF, LOGSCONF)". Actually most users log demand is very simple, a process to write a log file (using the logging handle layer functions), but also consider the other users have more than one output object demand (using the logging handle collection layer functions), and users tend to use external configuration file to configure the log (using a configuration file interface layer functions), different users in different project scene using iLOG3 different layers of the interface.
I also developed a sister function library iLOG3CONF_SML to support with SML markup language (XML) configuration file to configure the logging handle, interested friends can call log handle layer or log handle collection function to develop their own iLOG3CONF_ *, implementation in XML or json or in fashion now own project unified configuration file format, to achieve with an external configuration file configuration iLOG3 log handle to the environment.
In addition, the source code structure is relatively simple, only three pair of the source file, easy to handle, embedding and modification. (source behind analysis chapter to help readers understand and fork own version)
sample by call function :
[code=c]
#include <stdio.h>
#include "LOG.h"
#define LOG_STYLES_HELLO ( LOG_STYLE_DATETIMEMS | LOG_STYLE_LOGLEVEL | LOG_STYLE_PID | LOG_STYLE_TID | LOG_STYLE_SOURCE | LOG_STYLE_FORMAT | LOG_STYLE_NEWLINE )
int test_hello()
{
char buffer[ 64 + 1 ] = "" ;
long buflen = sizeof(buffer)-1 ;
/* Create log handle */
if(CreateLogHandleG() == NULL )
{
printf( "Failed to create log handle , errno[%d]\n" , errno );
return -1;
}
else
{
printf( "Create log handle success\n" );
}
/* Set the log output file name */
SetLogOutputG( LOG_OUTPUT_FILE , "test_iLOG3.log" , LOG_NO_OUTPUTFUNC );
/* Set the current log filter level */
SetLogLevelG( LOG_LEVEL_INFO );
/* Set the current line of log style */
SetLogStylesG( LOG_STYLES_HELLO , LOG_NO_STYLEFUNC);
/* write line log */
DEBUGLOGG( "hello DEBUG" );
INFOLOGG( "hello INFO" );
WARNLOGG( "hello WARN" );
ERRORLOGG( "hello ERROR" );
FATALLOGG( "hello FATAL" );
/* write hex piece log */
DEBUGHEXLOGG( buffer , buflen , "hello DEBUG buffer[%ld]" , buflen );
INFOHEXLOGG( buffer , buflen , "hello INFO buffer[%ld]" , buflen );
WARNHEXLOGG( buffer , buflen , "hello WARN buffer[%ld]" , buflen );
ERRORHEXLOGG( buffer , buflen , "hello ERROR buffer[%ld]" , buflen );
FATALHEXLOGG( buffer , buflen , "hello FATAL buffer[%ld]" , buflen );
/* Destruction of log handle */
DestroyLogHandleG();
printf( "Destruction of log handle\n" );
return 0;
}
int main()
{
return -test_hello();
}
[/code]
Explain, code first creates a log handle, set some attributes, and then brush brush to write the log, finally destroyed the log handle.
Compile and link and run
[code]
$ gcc -g -fPIC -Wall -Werror -O2 -I. -std=c99 -I/home/calvin/exinc/iLOG3 -c test_LOG.c
$ gcc -g -fPIC -Wall -Werror -O2 -o test_LOG test_LOG.o -L. -std=c99 -L/home/calvin/exlib -liLOG3
$ ./test_LOG
Create log handle success
Destruction of log handle
$ cat test_iLOG3.log
2014-02-10 00:26:07.418678 | INFO | 2045:3086292688:test_iLOG3.c:32 | hello INFO
2014-02-10 00:26:07.419236 | WARN | 2045:3086292688:test_iLOG3.c:33 | hello WARN
2014-02-10 00:26:07.419506 | ERROR | 2045:3086292688:test_iLOG3.c:34 | hello ERROR
2014-02-10 00:26:07.419518 | FATAL | 2045:3086292688:test_iLOG3.c:35 | hello FATAL
2014-02-10 00:26:07.419529 | INFO | 2045:3086292688:test_iLOG3.c:39 | hello INFO buffer[64]
0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
2014-02-10 00:26:07.419586 | WARN | 2045:3086292688:test_iLOG3.c:40 | hello WARN buffer[64]
0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
2014-02-10 00:26:07.419627 | ERROR | 2045:3086292688:test_iLOG3.c:41 | hello ERROR buffer[64]
0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
2014-02-10 00:26:07.419686 | FATAL | 2045:3086292688:test_iLOG3.c:42 | hello FATAL buffer[64]
0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
[/code]
sample by configure file
[code=c]
#include "LOGSCONF.h"
int test_logsconf( char *program )
{
LOGS *gs = NULL ;
char buffer[ 64 + 1 ] = "" ;
long buflen = sizeof(buffer) - 1 ;
/* Open the log handle collection from the configuration file */
gs = CreateLogsHandleFromConfigG( "test_logsconf.conf" , NULL ) ;
printf( "Open the log from configuration file handle collection of success\n" );
/* write line log */
DEBUGLOGG( "hello DEBUG" );
INFOLOGG( "hello INFO" );
WARNLOGG( "hello WARN" );
ERRORLOGG( "hello ERROR" );
FATALLOGG( "hello FATAL" );
/* write hex piece log */
DEBUGHEXLOGG( buffer , buflen , "hello DEBUG buffer[%ld]" , buflen );
INFOHEXLOGG( buffer , buflen , "hello INFO buffer[%ld]" , buflen );
WARNHEXLOGG( buffer , buflen , "hello WARN buffer[%ld]" , buflen );
ERRORHEXLOGG( buffer , buflen , "hello ERROR buffer[%ld]" , buflen );
FATALHEXLOGG( buffer , buflen , "hello FATAL buffer[%ld]" , buflen );
/* Destruction of log handle */
DestroyLogsHandleG();
printf( "Destruction of log handle\n" );
return 0;
}
int main( int argc , char *argv[] )
{
return -test_logsconf( argv[0] );
}
[/code]
test_logsconf.conf
[code]
id test_logsconf
output FILE test_logsconf.log
level INFO
styles DATETIME|LOGLEVEL|PID|TID|SOURCE|FORMAT|NEWLINE
options CHANGE_TEST
rotate_mode SIZE
rotate_size 10MB
log_bufsize 1MB 5MB
id stdout
output STDOUT
level INFO
styles DATETIME|LOGLEVEL|PID|TID|SOURCE|FORMAT|NEWLINE
[/code]
Pressure test of hardware
CPU : Intel Dual E2160 1.8GHz 1.81GHz
MEMORY : 2GB
HARDDISK : Seagate 250GB 7200
Pressure test software
Windows XP SP3 ( VMware 6.0 ( RedHat Enterprise Linux 5.4 MEMORY 256MB ) )
Pressure test scenarios
10 process, each process to open 10 threads, each thread to write article 10000 logs
go!
$ time ./test_press_mpt 10 10 10000 ; wc *.log*
real 0m13.922s
user 0m1.676s
sys 0m12.211s
124671 997368 9100983 test_press_mpt.log
148650 1189200 10851450 test_press_mpt.log.1
143668 1149344 10487764 test_press_mpt.log.2
143657 1149256 10486961 test_press_mpt.log.3
150482 1203856 10985186 test_press_mpt.log.4
143699 1149592 10490027 test_press_mpt.log.5
145173 1161384 10597629 test_press_mpt.log.6
1000000 8000000 73000000 total
In the source code contains a user guide and reference manual, there are more detailed instructions
iLOG3 User Guide.doc
indexes
1 Introduction 4
2 Overview 5
3 Compiler install 6
3.1 Dependency 6
3.2 With a makefile or VC6 project file compiler install 6
3.3 Manually compile installation 9
4 Basic use 9
4.1 A little concept 9
4.2 The first sample 10
4.3 Log style scheme selection 13
5 Advanced features 14
5.1 Set the log options 14
5.2 Log file rolling 14
5.3 Custom log style 15
5.4 Custom log output 16
5.5 Custom log open, output, close 17
5.6 Subsequent modification log file name 18
5.7 Thread-safe 19
5.7.1 MDC 19
5.7.2 Based on the default thread local storage global log handle 20
5.8 A common example 21
6 Log handle collection layer 22
7 The configuration file interface layer 25
7.1 The interface layer with simple configuration file 25
7.2 Looking forward 26
8 If you prefer simple log function to log function library
iLOG3 Reference Manual.doc
Indexes
1 Macros 6
1.1 Error code macros 6
1.2 The log output macros 6
1.3 Log level macro 6
1.4 Line logging combination style macros 7
1.5 Log options combination macro 8
1.6 Log rolling mode macro 8
2 Log handle functions 9
2.1 Admin log handle 9
2.1.1 Create log handle 9
2.1.2 Destruction of log handle 9
2.2 Handle the environment Settings 10
2.2.1 Set the log output 10
2.2.2 Set the current log filter level 10
2.2.3 Set line log style 11
2.3 Advanced handle environment Settings 11
2.3.1 Set the custom log filter callback function 11
2.3.2 Set the log handle options 11
2.3.3 Set the custom tag 12
2.3.4 Set log rolling mode 12
2.3.5 Set the log file rolling size 12
2.3.6 Set the size of the log file transfer file compression coefficient 13
2.3.7 Set the custom log file before the callback function 13
2.3.8 Set the custom log file after the callback function 13
2.3.9 Set line log buffer size 14
2.3.10 Set the hex piece of log buffer size 14
2.4 Line of log output 14
2.4.1 Write the line log with log level 14
2.4.2 Write line log with DEBUG level 15
2.4.3 Write line log with INFO level 15
2.4.4 Write line log with WARN level 16
2.4.5 Write line log with ERROR level 16
2.4.6 Write line log with FATAL level 16
2.5 Hex piece of log output 17
2.5.1 Write the hex piece log with log level 17
2.5.2 Write hex piece log with DEBUG level 17
2.5.3 Write hex piece log with INFO level 18
2.5.4 Write hex piece log with WARN level 18
2.5.5 Write hex piece log with ERROR level 19
2.5.6 Write hex piece log with FATAL level 19
3 The log handle collection functions 20
3.1 Admin log handle collection 20
3.1.1 Create log handle collection 20
3.1.2 Destruction of logging handle collection 20
3.2 Admin log log of a set of handle handle 21
3.2.1 Into a log to the log handle handle collection 21
3.2.2 From a log handle collection of pop up a log handle of the specified identification 21
3.2.3 From a query log handle the collection a log handle of the specified identification 22
3.2.4 Through a log in the collection of all log handle handle 22
4 Configuration file interface layer functions 23
4.1 Log handle 23
4.1.1 Handle to the build log from the config file 23
4.2 Log handle collection 23
4.2.1 The build log handle collection from the config file 23
5 Configuration of auxiliary function 24
5.1 Property transfer function 24
5.1.1 Log output type (string converted to an integer) 24
5.1.2 Log level types (string converted to an integer) 24
5.1.3 Log level types (integer is converted to a string) 24
5.1.4 Line log style (string converted to an integer) 25
5.1.5 Log option (string converted to an integer) 25
5.1.6 Log rolling mode (string is converted to an integer) 25
5.1.7 The log buffer (string converted to an integer) 26
6 Simple configuration file attributes list 26
Welcome to use, if you met with a problem or have a cool idea, please tell me, thank you ^_^
Portal home page
[url]https://github.com/calvinwilliams/iLOG3[/url]
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/jayfey/iLOG3.git
git@gitee.com:jayfey/iLOG3.git
jayfey
iLOG3
iLOG3
master

搜索帮助