-
Notifications
You must be signed in to change notification settings - Fork 26
/
test_demo.c
135 lines (113 loc) · 4.65 KB
/
test_demo.c
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <stdio.h>
#include <errno.h>
#include "LOG.h"
#define LOG_STYLES_DEMO ( LOG_STYLE_DATETIMEMS | LOG_STYLE_LOGLEVEL | LOG_STYLE_PID | LOG_STYLE_TID | LOG_STYLE_SOURCE | LOG_STYLE_FORMAT | LOG_STYLE_NEWLINE )
#define LOG_STYLES_DEMO2 ( LOG_STYLE_DATETIME | LOG_STYLE_FORMAT | LOG_STYLE_NEWLINE )
#define LOG_STYLES_EVENT ( LOG_STYLE_DATETIME | LOG_STYLE_CUSTLABEL1 | LOG_STYLE_FORMAT | LOG_STYLE_NEWLINE )
#define LOG_STYLES_SIMPLE ( LOG_STYLE_FORMAT | LOG_STYLE_NEWLINE )
int test_demo()
{
LOG *g = NULL , *g3 = NULL , *g4 = NULL ;
#if ( defined __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901 )
LOG *g2 = NULL ;
#endif
char buffer[ 64 + 1 ] = "" ;
long buflen = sizeof(buffer) - 1 ;
g = CreateLogHandle() ;
if( g == NULL )
{
printf( "创建日志句柄失败errno[%d]\n" , errno );
return -1;
}
SetLogOutput( g , LOG_OUTPUT_FILE , "test_demo.log" , LOG_NO_OUTPUTFUNC );
SetLogOutput2( g , LOG_OUTPUT_FILE , LOG_NO_OUTPUTFUNC , "%s/test_demo.log" , getenv("HOME") );
SetLogLevel( g , LOG_LEVEL_INFO );
SetLogStyles( g , LOG_STYLES_DEMO , LOG_NO_STYLEFUNC );
#if ( defined __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901 )
g2 = CreateLogHandle() ;
if( g2 == NULL )
{
printf( "创建日志句柄失败errno[%d]\n" , errno );
return -1;
}
SetLogOutput( g2 , LOG_OUTPUT_FILE , "$HOME$/test_hello2.log" , LOG_NO_OUTPUTFUNC );
SetLogLevel( g2 , LOG_LEVEL_INFO );
SetLogStyles( g2 , LOG_STYLES_DEMO , LOG_NO_STYLEFUNC );
#endif
#if ( defined _WIN32 ) || ( defined __linux__ ) || ( defined _AIX )
g3 = CreateLogHandleG() ;
if( g3 == NULL )
{
printf( "创建日志句柄失败errno[%d]\n" , errno );
return -1;
}
SetLogOutputG( LOG_OUTPUT_STDOUT , NULL , LOG_NO_OUTPUTFUNC );
SetLogLevelG( LOG_LEVEL_INFO );
SetLogStylesG( LOG_STYLES_EVENT , LOG_NO_STYLEFUNC );
SetLogCustLabelG( 1 , "COREIB1_SERVICE" );
#endif
g4 = CreateLogHandle() ;
if( g4 == NULL )
{
printf( "创建日志句柄失败errno[%d]\n" , errno );
return -1;
}
SetLogOutput( g4 , LOG_OUTPUT_SYSLOG , "test" , LOG_NO_OUTPUTFUNC );
SetLogLevel( g4 , LOG_LEVEL_INFO );
SetLogStyles( g4 , LOG_STYLES_SIMPLE , LOG_NO_STYLEFUNC );
printf( "创建日志句柄成功\n" );
WriteDebugLog( g , __FILE__ , __LINE__ , "hello iLOG3" );
WriteInfoLog( g , __FILE__ , __LINE__ , "hello iLOG3" );
WriteWarnLog( g , __FILE__ , __LINE__ , "hello iLOG3" );
WriteErrorLog( g , __FILE__ , __LINE__ , "hello iLOG3" );
WriteFatalLog( g , __FILE__ , __LINE__ , "hello iLOG3" );
WriteDebugHexLog( g , __FILE__ , __LINE__ , buffer , buflen , "缓冲区[%ld]" , buflen );
WriteInfoHexLog( g , __FILE__ , __LINE__ , buffer , buflen , "缓冲区[%ld]" , buflen );
WriteWarnHexLog( g , __FILE__ , __LINE__ , buffer , buflen , "缓冲区[%ld]" , buflen );
WriteErrorHexLog( g , __FILE__ , __LINE__ , buffer , buflen , "缓冲区[%ld]" , buflen );
WriteFatalHexLog( g , __FILE__ , __LINE__ , buffer , buflen , "缓冲区[%ld]" , buflen );
#if ( defined __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901 )
DEBUGLOG( g2 , "hello iLOG3" );
INFOLOG( g2 , "hello iLOG3" );
WARNLOG( g2 , "hello iLOG3" );
ERRORLOG( g2 , "hello iLOG3" );
FATALLOG( g2 , "hello iLOG3" );
DEBUGHEXLOG( g2 , buffer , buflen , "缓冲区[%ld]" , buflen );
INFOHEXLOG( g2 , buffer , buflen , "缓冲区[%ld]" , buflen );
WARNHEXLOG( g2 , buffer , buflen , "缓冲区[%ld]" , buflen );
ERRORHEXLOG( g2 , buffer , buflen , "缓冲区[%ld]" , buflen );
FATALHEXLOG( g2 , buffer , buflen , "缓冲区[%ld]" , buflen );
#endif
#if ( defined _WIN32 ) || ( defined __linux__ ) || ( defined _AIX )
WriteDebugLogG( __FILE__ , __LINE__ , "hello iLOG3" );
WriteInfoLogG( __FILE__ , __LINE__ , "hello iLOG3" );
WriteWarnLogG( __FILE__ , __LINE__ , "hello iLOG3" );
WriteErrorLogG( __FILE__ , __LINE__ , "hello iLOG3" );
WriteFatalLogG( __FILE__ , __LINE__ , "hello iLOG3" );
#if ( defined __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901 )
DEBUGHEXLOGG( buffer , buflen , "缓冲区[%ld]" , buflen );
INFOHEXLOGG( buffer , buflen , "缓冲区[%ld]" , buflen );
WARNHEXLOGG( buffer , buflen , "缓冲区[%ld]" , buflen );
ERRORHEXLOGG( buffer , buflen , "缓冲区[%ld]" , buflen );
FATALHEXLOGG( buffer , buflen , "缓冲区[%ld]" , buflen );
#endif
#endif
WriteDebugLog( g4 , __FILE__ , __LINE__ , "hello iLOG3" );
WriteInfoLog( g4 , __FILE__ , __LINE__ , "hello iLOG3" );
WriteWarnLog( g4 , __FILE__ , __LINE__ , "hello iLOG3" );
WriteErrorLog( g4 , __FILE__ , __LINE__ , "hello iLOG3" );
DestroyLogHandle( g );
#if ( defined __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901 )
DestroyLogHandle( g2 );
#endif
#if ( defined _WIN32 ) || ( defined __linux__ ) || ( defined _AIX )
DestroyLogHandleG();
#endif
DestroyLogHandle( g4 );
printf( "销毁日志句柄\n" );
return 0;
}
int main()
{
return -test_demo();
}