T-Box Basic dev
Loading...
Searching...
No Matches
slog.h
Go to the documentation of this file.
1
9
10#ifndef __SLOG_H__
11#define __SLOG_H__
12
13#if defined(_WIN32)
14#ifndef _SLOG_FUNC
15#define _SLOG_FUNC _declspec(dllexport)
16#endif /* _SLOG_FUNC */
17#elif defined(__unix) || defined(_AIX) || defined(__linux__) || defined(__hpux)
18#ifndef _SLOG_FUNC
19#define _SLOG_FUNC
20#endif /* _SLOG_FUNC */
21#endif /* _WIN32 */
22
23#if defined(_WIN32)
24#include <fcntl.h>
25#include <io.h>
26#include <share.h>
27#include <windows.h>
28#elif defined(__unix) || defined(_AIX) || defined(__linux__) || defined(__hpux)
29#include <fcntl.h>
30#include <pthread.h>
31#include <sys/time.h>
32#include <syslog.h>
33#include <unistd.h>
34#endif /* _WIN32 */
35
36#include <stdarg.h>
37#include <stdio.h>
38#include <string.h>
39#include <sys/stat.h>
40#include <sys/types.h>
41
49
50#ifdef __cplusplus
51extern "C"
52{
53#endif
54
62
70#define SLOG_ERROR_ALLOC -11
71#define SLOG_ERROR_INTERNAL -12
72#define SLOG_ERROR_ALLOC_MAX -13
73#define SLOG_ERROR_PARAMETER -14
74#define SLOG_ERROR_NOTSUPPORT -17
75#define SLOG_ERROR_CREATEFILE -21
76#define SLOG_ERROR_OPENFILE -22
77#define SLOG_ERROR_WRITEFILE -23
78#define SLOG_ERROR_TOO_MANY_STYLES -31
79#define SLOG_ERROR_CONFIGFILE_NOTFOUND -51
80#define SLOG_ERROR_CONFIGFILE_INVALID -52
84
92#define SLOG_OUTPUT_INVALID -1
93#define SLOG_OUTPUT_STDOUT 1
94#define SLOG_OUTPUT_STDERR 2
95#define SLOG_OUTPUT_SYSLOG 3
96#define SLOG_OUTPUT_FILE 11
97#define SLOG_OUTPUT_CALLBACK 21
101
110#define SLOG_LEVEL_INVALID -1
111#define SLOG_LEVEL_DEBUG 0
112#define SLOG_LEVEL_INFO 1
113#define SLOG_LEVEL_NOTICE 2
114#define SLOG_LEVEL_WARN 3
115#define SLOG_LEVEL_ERROR 4
116#define SLOG_LEVEL_FATAL 5
117#define SLOG_LEVEL_NOLOG 6
118#define SLOG_LEVEL_DEFAULT SLOG_LEVEL_NOLOG
122
131#define SLOG_STYLE_INVALID -1
132#define SLOG_STYLE_DATE 0x00001
133#define SLOG_STYLE_DATETIME 0x00002
134#define SLOG_STYLE_DATETIMEMS 0x00004
135#define SLOG_STYLE_LOGLEVEL 0x00008
136#define SLOG_STYLE_PID 0x00010
137#define SLOG_STYLE_TID 0x00020
138#define SLOG_STYLE_SOURCE 0x00040
139#define SLOG_STYLE_FORMAT 0x00080
140#define SLOG_STYLE_NEWLINE 0x00100
141#define SLOG_STYLE_CUSTLABEL1 0x00200
142#define SLOG_STYLE_CUSTLABEL2 0x00400
143#define SLOG_STYLE_CUSTLABEL3 0x00800
144#define SLOG_STYLE_CUSTLABEL4 0x01000
145#define SLOG_STYLE_CUSTLABEL5 0x02000
146#define SLOG_STYLE_CALLBACK 0x10000
147#define SLOG_STYLE_COLORFUL 0x20000
148#define SLOG_STYLE_LOGLEVEL_SHORT 0x40008
149#define SLOG_STYLES_DEFAULT 0
153
161
162#ifndef SLOG_MAX_FILE_NAME
163#define SLOG_MAX_FILE_NAME 256
164#endif
165
166#ifndef SLOG_MAX_FILE_TYPE
167#define SLOG_MAX_FILE_TYPE 8
168#endif
169
173
177
186
187typedef struct tagSLOG SLOG;
188typedef struct tagSLOGBUF SLOGBUF;
189
190typedef int funcOpenLog(SLOG* g, char* file, void** open_handle);
191
192typedef int funcWriteLog(SLOG* g, void** open_handle, int log_level, const void* buf, long len, long* writelen);
193
194typedef int funcChangeTest(SLOG* g, void** test_handle);
195
196typedef int funcCloseLog(SLOG* g, void** open_handle);
197
198typedef int funcLogStyle(SLOG* g, SLOGBUF* logbuf, char* c_filename, long c_fileline, int log_level, const char* format,
199 va_list valist);
200
201#define SLOG_NO_OUTPUTFUNC NULL, NULL, NULL, NULL, NULL, NULL
202
203#define SLOG_NO_STYLEFUNC NULL
204
208
217
218_SLOG_FUNC SLOG* CreateLogHandle();
219
220_SLOG_FUNC void DestroyLogHandle(SLOG* g);
221
222_SLOG_FUNC int GetLogOutput(SLOG* g);
223
224_SLOG_FUNC int SetLogOutput(SLOG* g, int output, const char* log_pathfilename, funcOpenLog* pfuncOpenLogPrepare,
225 funcOpenLog* pfuncOpenLog, funcWriteLog* pfuncWriteLog, funcChangeTest* pfuncChangeTest,
226 funcCloseLog* pfuncCloseLog, funcCloseLog* pfuncCloseLogEnd);
227
235_SLOG_FUNC int SetLogFileType(SLOG* g, const char* file_type);
236
237_SLOG_FUNC int SetLogOutput2(SLOG* g, int output, funcOpenLog* pfuncOpenLogPrepare, funcOpenLog* pfuncOpenLog,
238 funcWriteLog* pfuncWriteLog, funcChangeTest* pfuncChangeTest, funcCloseLog* pfuncCloseLog,
239 funcCloseLog* pfuncCloseLogEnd, char* log_pathfilename_format, ...);
240
241_SLOG_FUNC int ReOpenLogOutput(SLOG* g);
242
243_SLOG_FUNC int SetLogLevel(SLOG* g, int log_level);
244
245_SLOG_FUNC int SetLogStyles(SLOG* g, long log_styles, funcLogStyle* pfuncLogStyle);
246
247_SLOG_FUNC int SetLogStylesEx(SLOG* g, long log_styles, funcLogStyle* pfuncLogStyle, funcLogStyle* pfuncLogStylePrefix);
248
249_SLOG_FUNC int WriteLevelLog(SLOG* g, char* c_filename, long c_fileline, int log_level, const char* format, ...);
250
251_SLOG_FUNC int WriteDebugLog(SLOG* g, char* c_filename, long c_fileline, const char* format, ...);
252
253_SLOG_FUNC int WriteInfoLog(SLOG* g, char* c_filename, long c_fileline, const char* format, ...);
254
255_SLOG_FUNC int WriteNoticeLog(SLOG* g, char* c_filename, long c_fileline, const char* format, ...);
256
257_SLOG_FUNC int WriteWarnLog(SLOG* g, char* c_filename, long c_fileline, const char* format, ...);
258
259_SLOG_FUNC int WriteErrorLog(SLOG* g, char* c_filename, long c_fileline, const char* format, ...);
260
261_SLOG_FUNC int WriteFatalLog(SLOG* g, char* c_filename, long c_fileline, const char* format, ...);
262
263_SLOG_FUNC int WriteHexLog(SLOG* g, char* c_filename, long c_fileline, int log_level, const void* buffer, long buflen,
264 const char* format, ...);
265
266_SLOG_FUNC int WriteDebugHexLog(SLOG* g, char* c_filename, long c_fileline, const void* buffer, long buflen,
267 const char* format, ...);
268
269_SLOG_FUNC int WriteInfoHexLog(SLOG* g, char* c_filename, long c_fileline, const void* buffer, long buflen,
270 const char* format, ...);
271
272_SLOG_FUNC int WriteNoticeHexLog(SLOG* g, char* c_filename, long c_fileline, const void* buffer, long buflen,
273 const char* format, ...);
274
275_SLOG_FUNC int WriteWarnHexLog(SLOG* g, char* c_filename, long c_fileline, const void* buffer, long buflen,
276 const char* format, ...);
277
278_SLOG_FUNC int WriteErrorHexLog(SLOG* g, char* c_filename, long c_fileline, const void* buffer, long buflen,
279 const char* format, ...);
280
281_SLOG_FUNC int WriteFatalHexLog(SLOG* g, char* c_filename, long c_fileline, const void* buffer, long buflen,
282 const char* format, ...);
283
287
288#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
289
298#define WRITELOG(_g_, _log_level_, ...) WriteLevelLog(_g_, __FILE__, __LINE__, _log_level_, __VA_ARGS__)
299#define DEBUGLOG(_g_, ...) WriteDebugLog(_g_, __FILE__, __LINE__, __VA_ARGS__)
300#define INFOLOG(_g_, ...) WriteInfoLog(_g_, __FILE__, __LINE__, __VA_ARGS__)
301#define NOTICELOG(_g_, ...) WriteNoticeLog(_g_, __FILE__, __LINE__, __VA_ARGS__)
302#define WARNLOG(_g_, ...) WriteWarnLog(_g_, __FILE__, __LINE__, __VA_ARGS__)
303#define ERRORLOG(_g_, ...) WriteErrorLog(_g_, __FILE__, __LINE__, __VA_ARGS__)
304#define FATALLOG(_g_, ...) WriteFatalLog(_g_, __FILE__, __LINE__, __VA_ARGS__)
305
306#define WRITEHEXLOG(_g_, _log_level_, _buf_, _buf_size_, ...) \
307 WriteHexLog(_g_, __FILE__, __LINE__, _log_level_, _buf_, _buf_size_, __VA_ARGS__)
308#define DEBUGHEXLOG(_g_, _buf_, _buf_size_, ...) \
309 WriteDebugHexLog(_g_, __FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
310#define INFOHEXLOG(_g_, _buf_, _buf_size_, ...) WriteInfoHexLog(_g_, __FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
311#define NOTICEHEXLOG(_g_, _buf_, _buf_size_, ...) \
312 WriteNoticeHexLog(_g_, __FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
313#define WARNHEXLOG(_g_, _buf_, _buf_size_, ...) WriteWarnHexLog(_g_, __FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
314#define ERRORHEXLOG(_g_, _buf_, _buf_size_, ...) \
315 WriteErrorHexLog(_g_, __FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
316#define FATALHEXLOG(_g_, _buf_, _buf_size_, ...) \
317 WriteFatalHexLog(_g_, __FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
321#endif /* __STDC_VERSION__ && (__STDC_VERSION__ >= 199901) */
322
331#define create_log_handle CreateLogHandle
332#define destroy_log_handle DestroyLogHandle
333
334#define func_open_log funcOpenLog
335#define func_write_log funcWriteLog
336#define func_change_test funcChangeTest
337#define func_close_log funcCloseLog
338
339#define func_log_style funcLogStyle
340
341#define set_log_output SetLogOutput
342#define set_log_file_type SetLogFileType
343#define set_log_output2 SetLogOutput2
344#define set_log_level SetLogLevel
345#define set_log_styles SetLogStyles
346
347#define write_level_log WriteLevelLog
348#define write_debug_log WriteDebugLog
349#define write_info_log WriteInfoLog
350#define write_notice_log WriteNoticeLog
351#define write_warn_log WriteWarnLog
352#define write_error_log WriteErrorLog
353#define write_fatal_log WriteFatalLog
354
355#define write_hex_log WriteHexLog
356#define write_debug_hex_log WriteDebugHexLog
357#define write_info_hex_log WriteInfoHexLog
358#define write_notice_hex_log WriteNoticeHexLog
359#define write_warn_hex_log WriteWarnHexLog
360#define write_error_hex_log WriteErrorHexLog
361#define write_fatal_hex_log WriteFatalHexLog
365
366#if defined(_WIN32) || defined(__linux__) || defined(_AIX) || defined(__hpux)
367
376
385
386_SLOG_FUNC SLOG* CreateLogHandleG();
387
388_SLOG_FUNC void DestroyLogHandleG();
389
390_SLOG_FUNC SLOG* GetLogHandleG();
391
392_SLOG_FUNC void GetLogHandlePtrG(SLOG** pp_g);
393
394_SLOG_FUNC void SetLogHandleG(SLOG* g);
395
396_SLOG_FUNC int SetLogOutputG(int output, const char* log_pathfilename, funcOpenLog* pfuncOpenLogPrepare,
397 funcOpenLog* pfuncOpenLog, funcWriteLog* pfuncWriteLog, funcChangeTest* pfuncChangeTest,
398 funcCloseLog* pfuncCloseLog, funcCloseLog* pfuncCloseLogEnd);
399
400_SLOG_FUNC int SetLogFileTypeG(const char* file_type);
401
402_SLOG_FUNC int SetLogLevelG(int log_level);
403
404_SLOG_FUNC int SetLogStylesG(long log_styles, funcLogStyle* pfuncLogStyles);
405
406_SLOG_FUNC int SetLogStylesExG(long log_styles, funcLogStyle* pfuncLogStyles, funcLogStyle* pfuncLogStylePrefix);
407
408_SLOG_FUNC int SetLogOutput2V(SLOG* g, int output, funcOpenLog* pfuncOpenLogPrepare, funcOpenLog* pfuncOpenLog,
409 funcWriteLog* pfuncWriteLog, funcChangeTest* pfuncChangeTest, funcCloseLog* pfuncCloseLog,
410 funcCloseLog* pfuncCloseLogEnd, char* log_pathfilename_format, va_list valist);
411
412_SLOG_FUNC int SetLogOutput2G(int output, funcOpenLog* pfuncOpenLogPrepare, funcOpenLog* pfuncOpenLog,
413 funcWriteLog* pfuncWriteLog, funcChangeTest* pfuncChangeTest, funcCloseLog* pfuncCloseLog,
414 funcCloseLog* pfuncCloseLogEnd, char* log_pathfilename_format, ...);
415
416_SLOG_FUNC int ReOpenLogOutputG();
417
418_SLOG_FUNC int WriteLevelLogG(char* c_filename, long c_fileline, int log_level, const char* format, ...);
419
420_SLOG_FUNC int WriteDebugLogG(char* c_filename, long c_fileline, const char* format, ...);
421
422_SLOG_FUNC int WriteInfoLogG(char* c_filename, long c_fileline, const char* format, ...);
423
424_SLOG_FUNC int WriteNoticeLogG(char* c_filename, long c_fileline, const char* format, ...);
425
426_SLOG_FUNC int WriteWarnLogG(char* c_filename, long c_fileline, const char* format, ...);
427
428_SLOG_FUNC int WriteErrorLogG(char* c_filename, long c_fileline, const char* format, ...);
429
430_SLOG_FUNC int WriteFatalLogG(char* c_filename, long c_fileline, const char* format, ...);
431
432_SLOG_FUNC int WriteHexLogG(char* c_filename, long c_fileline, int log_level, const void* buffer, long buflen,
433 const char* format, ...);
434
435_SLOG_FUNC int WriteDebugHexLogG(char* c_filename, long c_fileline, const void* buffer, long buflen, const char* format,
436 ...);
437
438_SLOG_FUNC int WriteInfoHexLogG(char* c_filename, long c_fileline, const void* buffer, long buflen, const char* format,
439 ...);
440
441_SLOG_FUNC int WriteNoticeHexLogG(char* c_filename, long c_fileline, const void* buffer, long buflen,
442 const char* format, ...);
443
444_SLOG_FUNC int WriteWarnHexLogG(char* c_filename, long c_fileline, const void* buffer, long buflen, const char* format,
445 ...);
446
447_SLOG_FUNC int WriteErrorHexLogG(char* c_filename, long c_fileline, const void* buffer, long buflen, const char* format,
448 ...);
449
450_SLOG_FUNC int WriteFatalHexLogG(char* c_filename, long c_fileline, const void* buffer, long buflen, const char* format,
451 ...);
452
456
457#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
458
467
468#define WRITELOGG(_log_level_, ...) WriteLevelLogG(__FILE__, __LINE__, _log_level_, __VA_ARGS__)
469#define DEBUGLOGG(...) WriteDebugLogG(__FILE__, __LINE__, __VA_ARGS__)
470#define INFOLOGG(...) WriteInfoLogG(__FILE__, __LINE__, __VA_ARGS__)
471#define NOTICELOGG(...) WriteNoticeLogG(__FILE__, __LINE__, __VA_ARGS__)
472#define WARNLOGG(...) WriteWarnLogG(__FILE__, __LINE__, __VA_ARGS__)
473#define ERRORLOGG(...) WriteErrorLogG(__FILE__, __LINE__, __VA_ARGS__)
474#define FATALLOGG(...) WriteFatalLogG(__FILE__, __LINE__, __VA_ARGS__)
475
476#define WRITEHEXLOGG(_log_level_, _buf_, _buf_size_, ...) \
477 WriteLevelHexLogG(__FILE__, __LINE__, _log_level_, _buf_, _buf_size_, __VA_ARGS__)
478#define DEBUGHEXLOGG(_buf_, _buf_size_, ...) WriteDebugHexLogG(__FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
479#define INFOHEXLOGG(_buf_, _buf_size_, ...) WriteInfoHexLogG(__FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
480#define NOTICEHEXLOGG(_buf_, _buf_size_, ...) WriteNoticeHexLogG(__FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
481#define WARNHEXLOGG(_buf_, _buf_size_, ...) WriteWarnHexLogG(__FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
482#define ERRORHEXLOGG(_buf_, _buf_size_, ...) WriteErrorHexLogG(__FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
483#define FATALHEXLOGG(_buf_, _buf_size_, ...) WriteFatalHexLogG(__FILE__, __LINE__, _buf_, _buf_size_, __VA_ARGS__)
484
488
489#endif /* __STDC_VERSION__ */
490
499
500#define create_log_handle_g CreateLogHandleG
501#define destroy_log_handle_g DestroyLogHandleG
502
503#define set_log_output_g SetLogOutputG
504#define set_log_file_type_g SetLogFileTypeG
505#define set_log_level_g SetLogLevelG
506#define set_log_styles_g SetLogStylesG
507#define set_log_output2_g SetLogOutput2G
508
509#define write_level_log_g WriteLevelLogG
510#define write_debug_log_g WriteDebugLogG
511#define write_info_log_g WriteInfoLogG
512#define write_notice_log_g WriteNoticeLogG
513#define write_warn_log_g WriteWarnLogG
514#define write_error_log_g WriteErrorLogG
515#define write_fatal_log_g WriteFatalLogG
516
517#define write_hex_log_g WriteHexLogG
518#define write_debug_hex_log_g WriteDebugHexLogG
519#define write_info_hex_log_g WriteInfoHexLogG
520#define write_notice_hex_log_g WriteNoticeHexLogG
521#define write_warn_hex_log_g WriteWarnHexLogG
522#define write_error_hex_log_g WriteErrorHexLogG
523#define write_fatal_hex_log_g WriteFatalHexLogG
527
531
532#endif /* _WIN32 || __linux__ || _AIX || __hpux */
533
542
543typedef int funcFilterLog(SLOG* g, void** open_handle, int log_level, char* buf, long len);
544
545typedef int funcEncryptLog(SLOG* g, const char* plaintext, char* ciphertext, long len);
546
547#define func_filter_log funcFilterLog
548#define func_encrypt_log funcEncryptLog
549
550#define SLOG_MAXCNT_CUST_LABEL 5
551#define SLOG_MAXLEN_CUST_LABEL 64
552
553#define SLOG_OPTION_INVALID -1
554#define SLOG_OPTION_OPEN_AND_CLOSE 0x1
555#define SLOG_OPTION_CHANGE_TEST 0x2
556#define SLOG_OPTION_OPEN_ONCE 0x4
557#define SLOG_OPTION_SET_OUTPUT_BY_FILENAME 0x8
558#define SLOG_OPTION_ENCRYPT 0x10
559
560#define SLOG_OPTION_OPEN_DEFAULT SLOG_OPTION_CHANGE_TEST
561
562#define SLOG_CUST_LABELS_COUNT 30
563#define SLOG_ROTATEMODE_INVALID -1
564#define SLOG_ROTATEMODE_NONE 0
565#define SLOG_ROTATEMODE_SIZE 1
566#define SLOG_ROTATEMODE_PER_DAY 2
567#define SLOG_ROTATEMODE_PER_HOUR 3
568
569#define SLOG_ROTATE_SIZE_FILE_COUNT_DEFAULT 99999999
570#define SLOG_ROTATE_SIZE_PRESSURE_FACTOR_DEFAULT 0
571#define SLOG_FSYNC_PERIOD 10000
572
573typedef int funcBeforeRotateFile(SLOG* g, char* rotate_log_pathfilename);
574typedef int funcAfterRotateFile(SLOG* g, char* rotate_log_pathfilename);
575
576#define func_before_rotate_file funcBeforeRotateFile
577#define func_after_rotate_file funcAfterRotateFile
578
579#define SLOG_BUFSIZE_DEFAULT (1024)
580#define SLOG_BUFSIZE_MAX (1024 * 1024)
581#define SLOG_HEXLOG_BUFSIZE_DEFAULT (16 * 1024)
582#define SLOG_HEXLOG_BUFSIZE_MAX (10 * 1024 * 1024)
583
584_SLOG_FUNC int SetLogOptions(SLOG* g, int log_options);
585
586_SLOG_FUNC int SetLogFileChangeTest(SLOG* g, long interval);
587
588_SLOG_FUNC int SetLogFsyncPeriod(SLOG* g, long period);
589
590_SLOG_FUNC int SetLogCustLabel(SLOG* g, int index, char* cust_label);
591
592_SLOG_FUNC int SetLogRotateMode(SLOG* g, int rotate_mode);
593
594_SLOG_FUNC int SetLogRotateSize(SLOG* g, long log_rotate_size);
595
596_SLOG_FUNC int SetLogRotatePressureFactor(SLOG* g, long pressure_factor);
597
598_SLOG_FUNC int SetLogRotateFileCount(SLOG* g, long rotate_file_count);
599
600_SLOG_FUNC int SetLogRotateFileNo(SLOG* g, long rotate_file_no);
601
602_SLOG_FUNC long GetLogRotateFileNo(SLOG* g);
603
604_SLOG_FUNC int SetBeforeRotateFileFunc(SLOG* g, funcAfterRotateFile* pfuncAfterRotateFile);
605
606_SLOG_FUNC int SetAfterRotateFileFunc(SLOG* g, funcAfterRotateFile* pfuncAfterRotateFile);
607
608_SLOG_FUNC int SetFilterLogFunc(SLOG* g, funcFilterLog* pfuncFilterLog);
609
610_SLOG_FUNC int SetEncryptLogFunc(SLOG* g, funcEncryptLog* pfuncEncryptLog);
611
612_SLOG_FUNC int SetLogBufferSize(SLOG* g, long log_bufsize, long max_log_bufsize);
613
614_SLOG_FUNC int SetHexLogBufferSize(SLOG* g, long hexlog_bufsize, long max_log_hexbufsize);
615
616_SLOG_FUNC int SetLogOutputFuncDirectly(SLOG* g, funcOpenLog* pfuncOpenLogPrepare, funcOpenLog* pfuncOpenLog,
617 funcWriteLog* pfuncWriteLog, funcChangeTest* pfuncChangeTest,
618 funcCloseLog* pfuncCloseLog, funcCloseLog* pfuncCloseLogEnd);
619
620_SLOG_FUNC int SetLogStyleFuncDirectly(SLOG* g, funcLogStyle* pfuncLogStyle);
621
626#define set_log_options SetLogOptions
627#define set_log_file_change_test SetLogFileChangeTest
628#define set_log_fsync_period SetLogFsyncPeriod
629#define set_log_cust_label SetLogCustLabel
630#define set_log_rotate_mode SetLogRotateMode
631#define set_log_rotate_size SetLogRotateSize
632#define set_log_rotate_pressure_factor SetLogRotatePressureFactor
633#define set_log_rotate_file_count SetLogRotateFileCount
634#define set_log_rotate_file_no SetLogRotateFileNo
635#define get_log_rotate_file_no GetLogRotateFileNo
636#define set_before_rotate_file_func SetBeforeRotateFileFunc
637#define set_after_rotate_file_func SetAfterRotateFileFunc
638#define set_filter_log_func SetFilterLogFunc
639#define set_encrypt_log_func SetEncryptLogFunc
640#define set_log_buffer_size SetLogBufferSize
641#define set_hex_log_buffer_size SetHexLogBufferSize
642#define set_log_output_func_directly SetLogOutputFuncDirectly
643#define set_log_stlye_func_directly SetLogStyleFuncDirectly
647
648#if defined(_WIN32) || defined(__linux__) || defined(_AIX) || defined(__hpux)
649
650_SLOG_FUNC int SetLogOptionsG(int log_options);
651
652_SLOG_FUNC int SetLogFileChangeTestG(long interval);
653
654_SLOG_FUNC int SetLogFsyncPeriodG(long period);
655
656_SLOG_FUNC int SetLogCustLabelG(int index, char* cust_label);
657
658_SLOG_FUNC int SetLogRotateModeG(int rotate_mode);
659
660_SLOG_FUNC int SetLogRotateSizeG(long log_rotate_size);
661
662_SLOG_FUNC int SetLogRotatePressureFactorG(long pressure_factor);
663
664_SLOG_FUNC int SetLogRotateFileCountG(long rotate_file_count);
665
666_SLOG_FUNC int SetLogRotateFileNoG(long rotate_file_no);
667
668_SLOG_FUNC long GetLogRotateFileNoG(void);
669
670_SLOG_FUNC int SetBeforeRotateFileFuncG(funcAfterRotateFile* pfuncAfterRotateFile);
671
672_SLOG_FUNC int SetAfterRotateFileFuncG(funcAfterRotateFile* pfuncAfterRotateFile);
673
674_SLOG_FUNC int SetFilterLogFuncG(funcFilterLog* pfuncFilterLog);
675
676_SLOG_FUNC int SetEncryptLogFuncG(funcEncryptLog* pfuncEncryptLog);
677
678_SLOG_FUNC int SetLogBufferSizeG(long log_bufsize, long max_log_bufsize);
679
680_SLOG_FUNC int SetHexLogBufferSizeG(long hexlog_bufsize, long max_log_hexbufsize);
681
682_SLOG_FUNC int SetLogOutputFuncDirectlyG(funcOpenLog* pfuncOpenLogPrepare, funcOpenLog* pfuncOpenLog,
683 funcWriteLog* pfuncWriteLog, funcChangeTest* pfuncChangeTest,
684 funcCloseLog* pfuncCloseLog, funcCloseLog* pfuncCloseLogEnd);
685
686_SLOG_FUNC int SetLogStyleFuncDirectlyG(funcLogStyle* pfuncLogStyle);
687
688#endif /* _WIN32 || __linux__ || _AIX || __hpux */
689
694#define set_log_options_g SetLogOptionsG
695#define set_log_file_change_test_g SetLogFileChangeTestG
696#define set_log_fsync_period_g SetLogFsyncPeriodG
697#define set_log_cust_label_g SetLogCustLabelG
698#define set_log_rotate_mode_g SetLogRotateModeG
699#define set_log_rotate_size_g SetLogRotateSizeG
700#define set_log_rotate_pressure_factor_g SetLogRotatePressureFactorG
701#define set_log_rotate_file_count_g SetLogRotateFileCountG
702#define set_log_rotate_file_no_g SetLogRotateFileNoG
703#define get_log_rotate_file_no_g GetLogRotateFileNoG
704#define set_before_rotate_file_func_g SetBeforeRotateFileFuncG
705#define set_after_rotate_file_func_g SetAfterRotateFileFuncG
706#define set_filter_log_func_g SetFilterLogFuncG
707#define set_log_buffer_size_g SetLogBufferSizeG
708#define set_hex_log_buffer_size_g SetHexLogBufferSizeG
709#define set_log_output_func_directly_g SetLogOutputFuncDirectlyG
710#define set_log_stlye_func_directly_g SetLogStyleFuncDirectlyG
714
718
719#define TEST_LOGLEVEL_NOTENOUGH(_log_level_, _g_) ((_log_level_) < GetLogLevel(_g_))
720
721#define SET_ATTRIBUTE(_param_, _attr_) ((_param_) = (_attr_))
722#define ADD_ATTRIBUTE(_param_, _attr_) ((_param_) |= (_attr_))
723#define REMOVE_ATTRIBUTE(_param_, _attr_) ((_param_) &= ~(_attr_))
724#define TEST_ATTRIBUTE(_param_, _attr_) (((_param_) & (_attr_)) == (_attr_))
725#define TEST_NO_ATTRIBUTE(_param_, _attr_) (((_param_) & (_attr_)) != (_attr_))
726
727#define TEST_STDSTREAM(_fd_) ((_fd_) != FD_NULL && ((_fd_) == STDOUT_HANDLE || (_fd_) == STDERR_HANDLE))
728#define TEST_FILEFD(_fd_) ((_fd_) != FD_NULL && (_fd_) != STDOUT_HANDLE && (_fd_) != STDERR_HANDLE)
729
730#if defined(_WIN32) || defined(__linux__) || defined(_AIX) || defined(__hpux)
731
732_SLOG_FUNC SLOG* GetGlobalLOG();
733
734_SLOG_FUNC void SetGlobalLOG(SLOG* g);
735
740#define get_global_log GetGlobalLOG
741#define set_global_log SetGlobalLOG
745
746#endif /* _WIN32 || __linux__ || _AIX || __hpux */
747
754
755#if defined(_WIN32)
756
757#define LOG_NEWLINE "\r\n"
758#define LOG_NEWLINE_LEN 2
759#define SNPRINTF _snprintf
760#define VSNPRINTF _vsnprintf
761#define STDOUT_HANDLE 1
762#define STDERR_HANDLE 2
763#define FD_NULL -1
764#define WRITE _write
765#define STAT _stat
766#define FSTAT _fstat
767#define ACCESS _access
768#define ACCESS_OK 00
769#define RENAME rename
770#define UNLINK unlink
771
772#elif defined(__unix) || defined(_AIX) || defined(__linux__) || defined(__hpux)
773
774#define LOG_NEWLINE "\n"
775#define LOG_NEWLINE_LEN 1
776#define SNPRINTF snprintf
777#define VSNPRINTF vsnprintf
778#define STDOUT_HANDLE STDOUT_FILENO
779#define STDERR_HANDLE STDERR_FILENO
780#define FD_NULL -1
781#define WRITE write
782#define STAT stat
783#define FSTAT fstat
784#define ACCESS access
785#define ACCESS_OK F_OK
786#define RENAME rename
787#define UNLINK unlink
788
789#endif /* _WIN32 */
790
791#if defined(_WIN32)
792
793#define SYSTEMTIME2TIMEVAL_USEC(_syst_, _tv_) (_tv_).tv_usec = (_syst_).wMilliseconds * 1000;
794
795#define SYSTEMTIME2TM(_syst_, _stime_) \
796 (_stime_).tm_year = (_syst_).wYear - 1900; \
797 (_stime_).tm_mon = (_syst_).wMonth - 1; \
798 (_stime_).tm_mday = (_syst_).wDay; \
799 (_stime_).tm_hour = (_syst_).wHour; \
800 (_stime_).tm_min = (_syst_).wMinute; \
801 (_stime_).tm_sec = (_syst_).wSecond;
802
803#define LOCALTIME(_tt_, _stime_) \
804 { \
805 SYSTEMTIME stNow; \
806 GetLocalTime(&stNow); \
807 SYSTEMTIME2TM(stNow, (_stime_)); \
808 }
809
810#elif defined(__unix) || defined(_AIX) || defined(__linux__) || defined(__hpux)
811
812#define LOCALTIME(_tt_, _stime_) localtime_r(&(_tt_), &(_stime_));
813
814#endif /* _WIN32 */
815
816#ifndef STRCMP
817#define STRCMP(_a_, _C_, _b_) (strcmp(_a_, _b_) _C_ 0)
818#define STRNCMP(_a_, _C_, _b_, _n_) (strncmp(_a_, _b_, _n_) _C_ 0)
819#endif /* STRCMP */
820
824
825#define OFFSET_BUFPTR(_logbuf_, _offset_len_) \
826 if (_offset_len_ > 0 && _offset_len_ <= (_logbuf_)->buf_remain_len && (_logbuf_)->bufptr[0]) \
827 { \
828 (_logbuf_)->bufptr += _offset_len_; \
829 (_logbuf_)->buf_remain_len -= _offset_len_; \
830 }
831
832#define OFFSET_BUFPTR_IN_LOOP(_logbuf_, _offset_len_) \
833 if (_offset_len_ > 0 && _offset_len_ <= (_logbuf_)->buf_remain_len && (_logbuf_)->bufptr[0]) \
834 { \
835 (_logbuf_)->bufptr += _offset_len_; \
836 (_logbuf_)->buf_remain_len -= _offset_len_; \
837 } \
838 else \
839 { \
840 break; \
841 }
842
843_SLOG_FUNC char* GetLogPathfilename(SLOG* g);
844_SLOG_FUNC int SetOpenFlag(SLOG* g, char open_flag);
845_SLOG_FUNC char IsLogOpened(SLOG* g);
846_SLOG_FUNC void* GetLogOpenHandle(SLOG* g);
847_SLOG_FUNC void SetLogOpenHandle(SLOG* g, void* open_handle);
848
849_SLOG_FUNC int GetLogLevel(SLOG* g);
850
851_SLOG_FUNC SLOGBUF* GetLogBuffer(SLOG* g);
852_SLOG_FUNC SLOGBUF* GetHexLogBuffer(SLOG* g);
853
854_SLOG_FUNC void CleanLogBuffer(SLOG* g, SLOGBUF* logbuf);
855_SLOG_FUNC long FormatLogBuffer(SLOG* g, SLOGBUF* logbuf, const char* format, ...);
856_SLOG_FUNC long FormatLogBufferV(SLOG* g, SLOGBUF* logbuf, const char* format, va_list valist);
857_SLOG_FUNC long MemcatLogBuffer(SLOG* g, SLOGBUF* logbuf, char* append, long len);
858
863#define set_open_flag SetOpenFlag
864#define is_log_opened IsLogOpened
865
866#define get_log_level GetLogLevel
867
868#define get_log_buffer GetLogBuffer
869#define get_hex_log_buffer GetHexLogBuffer
870
871#define format_log_buffer FormatLogBuffer
872#define format_log_buffer_v FormatLogBufferV
873#define memcat_log_buffer MemcatLogBuffer
877
878_SLOG_FUNC int ConvertLogOutput_atoi(char* output_desc);
879_SLOG_FUNC int ConvertLogLevel_atoi(char* log_level_desc);
880_SLOG_FUNC int ConvertLogLevels_atoi(char log_level_desc);
881_SLOG_FUNC const char* ConvertLogLevel_itoa(int log_level);
882_SLOG_FUNC const char ConvertLogLevels_itoa(int log_level);
883_SLOG_FUNC long ConvertLogStyle_atol(char* line_style_desc);
884_SLOG_FUNC long ConvertLogOption_atol(char* log_option_desc);
885_SLOG_FUNC int ConvertLogRotateMode_atoi(char* rotate_mode_desc);
886_SLOG_FUNC long ConvertBufferSize_atol(char* bufsize_desc);
887
892#define convert_log_output_atoi ConvertLogOutput_atoi
893#define convert_log_level_atoi ConvertLogLevel_atoi
894#define convert_log_levels_atoi ConvertLogLevels_atoi
895#define convert_log_level_itoa ConvertLogLevel_itoa
896#define convert_log_levels_itoa ConvertLogLevels_itoa
897#define convert_log_style_atol ConvertLogStyle_atol
898#define cnovert_log_option_atol ConvertLogOption_atol
899#define convert_log_rotate_mode_atoi ConvertLogRotateMode_atoi
900#define convert_buffer_size_atol ConvertBufferSize_atol
904
905_SLOG_FUNC int ExpandPathFilename(char* pathfilename, long pathfilename_bufsize);
906
907#ifdef __cplusplus
908}
909#endif
910
914
915#endif /* __SLOG_H__ */
_SLOG_FUNC int ConvertLogOutput_atoi(char *output_desc)
slog_apis_style_cover
_SLOG_FUNC int ExpandPathFilename(char *pathfilename, long pathfilename_bufsize)
slog_apis_style_cover
_SLOG_FUNC int SetLogFileType(SLOG *g, const char *file_type)
设置日志文件类型。
struct tagSLOGBUF SLOGBUF
日志缓冲区句柄
Definition slog.h:188
struct tagSLOG SLOG
日志句柄
Definition slog.h:187