T-Box Basic dev
Loading...
Searching...
No Matches
slog.h File Reference

日志接口 More...

#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>

Go to the source code of this file.

Macros

#define SLOG_ERROR_ALLOC   -11
 申请内存失败
#define SLOG_ERROR_INTERNAL   -12
 内部错误
#define SLOG_ERROR_ALLOC_MAX   -13
 内存使用超限
#define SLOG_ERROR_PARAMETER   -14
 参数错误
#define SLOG_ERROR_NOTSUPPORT   -17
 暂不支持
#define SLOG_ERROR_CREATEFILE   -21
 创建文件失败
#define SLOG_ERROR_OPENFILE   -22
 打开文件失败
#define SLOG_ERROR_WRITEFILE   -23
 写文件失败
#define SLOG_ERROR_TOO_MANY_STYLES   -31
 风格列太多了
#define SLOG_ERROR_CONFIGFILE_NOTFOUND   -51
 找不到配置文件
#define SLOG_ERROR_CONFIGFILE_INVALID   -52
 配置文件无效
#define SLOG_OUTPUT_INVALID   -1
 无效输出
#define SLOG_OUTPUT_STDOUT   1
 标准输出
#define SLOG_OUTPUT_STDERR   2
 标准错误
#define SLOG_OUTPUT_SYSLOG   3
 系统日志
#define SLOG_OUTPUT_FILE   11
 文件输出
#define SLOG_OUTPUT_CALLBACK   21
 回调输出
#define SLOG_LEVEL_INVALID   -1
 无效日志级别
#define SLOG_LEVEL_DEBUG   0
 调试日志级别
#define SLOG_LEVEL_INFO   1
 信息日志级别
#define SLOG_LEVEL_NOTICE   2
 通知日志级别
#define SLOG_LEVEL_WARN   3
 警告日志级别
#define SLOG_LEVEL_ERROR   4
 错误日志级别
#define SLOG_LEVEL_FATAL   5
 致命错误日志级别
#define SLOG_LEVEL_NOLOG   6
 不记录日志级别
#define SLOG_LEVEL_DEFAULT   SLOG_LEVEL_NOLOG
 默认日志级别
#define SLOG_STYLE_INVALID   -1
 无效日志样式
#define SLOG_STYLE_DATE   0x00001
 日期样式
#define SLOG_STYLE_DATETIME   0x00002
 日期时间样式
#define SLOG_STYLE_DATETIMEMS   0x00004
 日期时间毫秒样式
#define SLOG_STYLE_LOGLEVEL   0x00008
 日志级别样式
#define SLOG_STYLE_PID   0x00010
 进程ID样式
#define SLOG_STYLE_TID   0x00020
 线程ID样式
#define SLOG_STYLE_SOURCE   0x00040
 源样式
#define SLOG_STYLE_FORMAT   0x00080
 格式样式
#define SLOG_STYLE_NEWLINE   0x00100
 换行样式
#define SLOG_STYLE_CUSTLABEL1   0x00200
 自定义标签1样式
#define SLOG_STYLE_CUSTLABEL2   0x00400
 自定义标签2样式
#define SLOG_STYLE_CUSTLABEL3   0x00800
 自定义标签3样式
#define SLOG_STYLE_CUSTLABEL4   0x01000
 自定义标签4样式
#define SLOG_STYLE_CUSTLABEL5   0x02000
 自定义标签5样式
#define SLOG_STYLE_CALLBACK   0x10000
 回调样式
#define SLOG_STYLE_COLORFUL   0x20000
 颜色样式
#define SLOG_STYLE_LOGLEVEL_SHORT   0x40008
 短日志级别样式
#define SLOG_STYLES_DEFAULT   0
 默认日志样式
#define SLOG_MAX_FILE_NAME   256
 最大文件名长度
#define SLOG_MAX_FILE_TYPE   8
 最大文件类型长度
#define SLOG_NO_OUTPUTFUNC   NULL, NULL, NULL, NULL, NULL, NULL
#define SLOG_NO_STYLEFUNC   NULL
#define create_log_handle   CreateLogHandle
 创建日志句柄
#define destroy_log_handle   DestroyLogHandle
 销毁日志句柄
#define func_open_log   funcOpenLog
 打开日志文件
#define func_write_log   funcWriteLog
 写入日志
#define func_change_test   funcChangeTest
 切换测试日志
#define func_close_log   funcCloseLog
 关闭日志文件
#define func_log_style   funcLogStyle
 日志样式
#define set_log_output   SetLogOutput
 设置日志输出
#define set_log_file_type   SetLogFileType
 设置日志文件类型
#define set_log_output2   SetLogOutput2
 设置日志输出2
#define set_log_level   SetLogLevel
 设置日志级别
#define set_log_styles   SetLogStyles
 设置日志样式
#define write_level_log   WriteLevelLog
 写入日志级别
#define write_debug_log   WriteDebugLog
 写入调试日志
#define write_info_log   WriteInfoLog
 写入信息日志
#define write_notice_log   WriteNoticeLog
 写入通知日志
#define write_warn_log   WriteWarnLog
 写入警告日志
#define write_error_log   WriteErrorLog
 写入错误日志
#define write_fatal_log   WriteFatalLog
 写入致命错误日志
#define write_hex_log   WriteHexLog
 写入日志级别十六进制
#define write_debug_hex_log   WriteDebugHexLog
 写入调试日志十六进制
#define write_info_hex_log   WriteInfoHexLog
 写入信息日志十六进制
#define write_notice_hex_log   WriteNoticeHexLog
 写入通知日志十六进制
#define write_warn_hex_log   WriteWarnHexLog
 写入警告日志十六进制
#define write_error_hex_log   WriteErrorHexLog
 写入错误日志十六进制
#define write_fatal_hex_log   WriteFatalHexLog
 写入致命错误日志十六进制
#define func_filter_log   funcFilterLog
#define func_encrypt_log   funcEncryptLog
#define SLOG_MAXCNT_CUST_LABEL   5
#define SLOG_MAXLEN_CUST_LABEL   64
#define SLOG_OPTION_INVALID   -1
#define SLOG_OPTION_OPEN_AND_CLOSE   0x1
#define SLOG_OPTION_CHANGE_TEST   0x2
#define SLOG_OPTION_OPEN_ONCE   0x4
#define SLOG_OPTION_SET_OUTPUT_BY_FILENAME   0x8
#define SLOG_OPTION_ENCRYPT   0x10
#define SLOG_OPTION_OPEN_DEFAULT   SLOG_OPTION_CHANGE_TEST
#define SLOG_CUST_LABELS_COUNT   30
#define SLOG_ROTATEMODE_INVALID   -1
#define SLOG_ROTATEMODE_NONE   0
#define SLOG_ROTATEMODE_SIZE   1
#define SLOG_ROTATEMODE_PER_DAY   2
#define SLOG_ROTATEMODE_PER_HOUR   3
#define SLOG_ROTATE_SIZE_FILE_COUNT_DEFAULT   99999999
#define SLOG_ROTATE_SIZE_PRESSURE_FACTOR_DEFAULT   0
#define SLOG_FSYNC_PERIOD   10000
#define func_before_rotate_file   funcBeforeRotateFile
#define func_after_rotate_file   funcAfterRotateFile
#define SLOG_BUFSIZE_DEFAULT   (1024)
#define SLOG_BUFSIZE_MAX   (1024 * 1024)
#define SLOG_HEXLOG_BUFSIZE_DEFAULT   (16 * 1024)
#define SLOG_HEXLOG_BUFSIZE_MAX   (10 * 1024 * 1024)
#define set_log_options   SetLogOptions
#define set_log_file_change_test   SetLogFileChangeTest
#define set_log_fsync_period   SetLogFsyncPeriod
#define set_log_cust_label   SetLogCustLabel
#define set_log_rotate_mode   SetLogRotateMode
#define set_log_rotate_size   SetLogRotateSize
#define set_log_rotate_pressure_factor   SetLogRotatePressureFactor
#define set_log_rotate_file_count   SetLogRotateFileCount
#define set_log_rotate_file_no   SetLogRotateFileNo
#define get_log_rotate_file_no   GetLogRotateFileNo
#define set_before_rotate_file_func   SetBeforeRotateFileFunc
#define set_after_rotate_file_func   SetAfterRotateFileFunc
#define set_filter_log_func   SetFilterLogFunc
#define set_encrypt_log_func   SetEncryptLogFunc
#define set_log_buffer_size   SetLogBufferSize
#define set_hex_log_buffer_size   SetHexLogBufferSize
#define set_log_output_func_directly   SetLogOutputFuncDirectly
#define set_log_stlye_func_directly   SetLogStyleFuncDirectly
#define set_log_options_g   SetLogOptionsG
#define set_log_file_change_test_g   SetLogFileChangeTestG
#define set_log_fsync_period_g   SetLogFsyncPeriodG
#define set_log_cust_label_g   SetLogCustLabelG
#define set_log_rotate_mode_g   SetLogRotateModeG
#define set_log_rotate_size_g   SetLogRotateSizeG
#define set_log_rotate_pressure_factor_g   SetLogRotatePressureFactorG
#define set_log_rotate_file_count_g   SetLogRotateFileCountG
#define set_log_rotate_file_no_g   SetLogRotateFileNoG
#define get_log_rotate_file_no_g   GetLogRotateFileNoG
#define set_before_rotate_file_func_g   SetBeforeRotateFileFuncG
#define set_after_rotate_file_func_g   SetAfterRotateFileFuncG
#define set_filter_log_func_g   SetFilterLogFuncG
#define set_log_buffer_size_g   SetLogBufferSizeG
#define set_hex_log_buffer_size_g   SetHexLogBufferSizeG
#define set_log_output_func_directly_g   SetLogOutputFuncDirectlyG
#define set_log_stlye_func_directly_g   SetLogStyleFuncDirectlyG
#define TEST_LOGLEVEL_NOTENOUGH(_log_level_, _g_)
 slog_optional
#define SET_ATTRIBUTE(_param_, _attr_)
#define ADD_ATTRIBUTE(_param_, _attr_)
#define REMOVE_ATTRIBUTE(_param_, _attr_)
#define TEST_ATTRIBUTE(_param_, _attr_)
#define TEST_NO_ATTRIBUTE(_param_, _attr_)
#define TEST_STDSTREAM(_fd_)
#define TEST_FILEFD(_fd_)
#define STRCMP(_a_, _C_, _b_)
#define STRNCMP(_a_, _C_, _b_, _n_)
#define OFFSET_BUFPTR(_logbuf_, _offset_len_)
 slog_hook
#define OFFSET_BUFPTR_IN_LOOP(_logbuf_, _offset_len_)
#define set_open_flag   SetOpenFlag
#define is_log_opened   IsLogOpened
#define get_log_level   GetLogLevel
#define get_log_buffer   GetLogBuffer
#define get_hex_log_buffer   GetHexLogBuffer
#define format_log_buffer   FormatLogBuffer
#define format_log_buffer_v   FormatLogBufferV
#define memcat_log_buffer   MemcatLogBuffer
#define convert_log_output_atoi   ConvertLogOutput_atoi
#define convert_log_level_atoi   ConvertLogLevel_atoi
#define convert_log_levels_atoi   ConvertLogLevels_atoi
#define convert_log_level_itoa   ConvertLogLevel_itoa
#define convert_log_levels_itoa   ConvertLogLevels_itoa
#define convert_log_style_atol   ConvertLogStyle_atol
#define cnovert_log_option_atol   ConvertLogOption_atol
#define convert_log_rotate_mode_atoi   ConvertLogRotateMode_atoi
#define convert_buffer_size_atol   ConvertBufferSize_atol

Typedefs

typedef struct tagSLOG SLOG
 日志句柄
typedef struct tagSLOGBUF SLOGBUF
 日志缓冲区句柄
typedef int funcOpenLog(SLOG *g, char *file, void **open_handle)
typedef int funcWriteLog(SLOG *g, void **open_handle, int log_level, const void *buf, long len, long *writelen)
typedef int funcChangeTest(SLOG *g, void **test_handle)
typedef int funcCloseLog(SLOG *g, void **open_handle)
typedef int funcLogStyle(SLOG *g, SLOGBUF *logbuf, char *c_filename, long c_fileline, int log_level, const char *format, va_list valist)
typedef int funcFilterLog(SLOG *g, void **open_handle, int log_level, char *buf, long len)
typedef int funcEncryptLog(SLOG *g, const char *plaintext, char *ciphertext, long len)
typedef int funcBeforeRotateFile(SLOG *g, char *rotate_log_pathfilename)
typedef int funcAfterRotateFile(SLOG *g, char *rotate_log_pathfilename)

Functions

_SLOG_FUNC SLOGCreateLogHandle ()
_SLOG_FUNC void DestroyLogHandle (SLOG *g)
_SLOG_FUNC int GetLogOutput (SLOG *g)
_SLOG_FUNC int SetLogOutput (SLOG *g, int output, const char *log_pathfilename, funcOpenLog *pfuncOpenLogPrepare, funcOpenLog *pfuncOpenLog, funcWriteLog *pfuncWriteLog, funcChangeTest *pfuncChangeTest, funcCloseLog *pfuncCloseLog, funcCloseLog *pfuncCloseLogEnd)
_SLOG_FUNC int SetLogFileType (SLOG *g, const char *file_type)
 设置日志文件类型。
_SLOG_FUNC int SetLogOutput2 (SLOG *g, int output, funcOpenLog *pfuncOpenLogPrepare, funcOpenLog *pfuncOpenLog, funcWriteLog *pfuncWriteLog, funcChangeTest *pfuncChangeTest, funcCloseLog *pfuncCloseLog, funcCloseLog *pfuncCloseLogEnd, char *log_pathfilename_format,...)
_SLOG_FUNC int ReOpenLogOutput (SLOG *g)
_SLOG_FUNC int SetLogLevel (SLOG *g, int log_level)
_SLOG_FUNC int SetLogStyles (SLOG *g, long log_styles, funcLogStyle *pfuncLogStyle)
_SLOG_FUNC int SetLogStylesEx (SLOG *g, long log_styles, funcLogStyle *pfuncLogStyle, funcLogStyle *pfuncLogStylePrefix)
_SLOG_FUNC int WriteLevelLog (SLOG *g, char *c_filename, long c_fileline, int log_level, const char *format,...)
_SLOG_FUNC int WriteDebugLog (SLOG *g, char *c_filename, long c_fileline, const char *format,...)
_SLOG_FUNC int WriteInfoLog (SLOG *g, char *c_filename, long c_fileline, const char *format,...)
_SLOG_FUNC int WriteNoticeLog (SLOG *g, char *c_filename, long c_fileline, const char *format,...)
_SLOG_FUNC int WriteWarnLog (SLOG *g, char *c_filename, long c_fileline, const char *format,...)
_SLOG_FUNC int WriteErrorLog (SLOG *g, char *c_filename, long c_fileline, const char *format,...)
_SLOG_FUNC int WriteFatalLog (SLOG *g, char *c_filename, long c_fileline, const char *format,...)
_SLOG_FUNC int WriteHexLog (SLOG *g, char *c_filename, long c_fileline, int log_level, const void *buffer, long buflen, const char *format,...)
_SLOG_FUNC int WriteDebugHexLog (SLOG *g, char *c_filename, long c_fileline, const void *buffer, long buflen, const char *format,...)
_SLOG_FUNC int WriteInfoHexLog (SLOG *g, char *c_filename, long c_fileline, const void *buffer, long buflen, const char *format,...)
_SLOG_FUNC int WriteNoticeHexLog (SLOG *g, char *c_filename, long c_fileline, const void *buffer, long buflen, const char *format,...)
_SLOG_FUNC int WriteWarnHexLog (SLOG *g, char *c_filename, long c_fileline, const void *buffer, long buflen, const char *format,...)
_SLOG_FUNC int WriteErrorHexLog (SLOG *g, char *c_filename, long c_fileline, const void *buffer, long buflen, const char *format,...)
_SLOG_FUNC int WriteFatalHexLog (SLOG *g, char *c_filename, long c_fileline, const void *buffer, long buflen, const char *format,...)
_SLOG_FUNC int SetLogOptions (SLOG *g, int log_options)
_SLOG_FUNC int SetLogFileChangeTest (SLOG *g, long interval)
_SLOG_FUNC int SetLogFsyncPeriod (SLOG *g, long period)
_SLOG_FUNC int SetLogCustLabel (SLOG *g, int index, char *cust_label)
_SLOG_FUNC int SetLogRotateMode (SLOG *g, int rotate_mode)
_SLOG_FUNC int SetLogRotateSize (SLOG *g, long log_rotate_size)
_SLOG_FUNC int SetLogRotatePressureFactor (SLOG *g, long pressure_factor)
_SLOG_FUNC int SetLogRotateFileCount (SLOG *g, long rotate_file_count)
_SLOG_FUNC int SetLogRotateFileNo (SLOG *g, long rotate_file_no)
_SLOG_FUNC long GetLogRotateFileNo (SLOG *g)
_SLOG_FUNC int SetBeforeRotateFileFunc (SLOG *g, funcAfterRotateFile *pfuncAfterRotateFile)
_SLOG_FUNC int SetAfterRotateFileFunc (SLOG *g, funcAfterRotateFile *pfuncAfterRotateFile)
_SLOG_FUNC int SetFilterLogFunc (SLOG *g, funcFilterLog *pfuncFilterLog)
_SLOG_FUNC int SetEncryptLogFunc (SLOG *g, funcEncryptLog *pfuncEncryptLog)
_SLOG_FUNC int SetLogBufferSize (SLOG *g, long log_bufsize, long max_log_bufsize)
_SLOG_FUNC int SetHexLogBufferSize (SLOG *g, long hexlog_bufsize, long max_log_hexbufsize)
_SLOG_FUNC int SetLogOutputFuncDirectly (SLOG *g, funcOpenLog *pfuncOpenLogPrepare, funcOpenLog *pfuncOpenLog, funcWriteLog *pfuncWriteLog, funcChangeTest *pfuncChangeTest, funcCloseLog *pfuncCloseLog, funcCloseLog *pfuncCloseLogEnd)
_SLOG_FUNC int SetLogStyleFuncDirectly (SLOG *g, funcLogStyle *pfuncLogStyle)
_SLOG_FUNC char * GetLogPathfilename (SLOG *g)
_SLOG_FUNC int SetOpenFlag (SLOG *g, char open_flag)
_SLOG_FUNC char IsLogOpened (SLOG *g)
_SLOG_FUNC void * GetLogOpenHandle (SLOG *g)
_SLOG_FUNC void SetLogOpenHandle (SLOG *g, void *open_handle)
_SLOG_FUNC int GetLogLevel (SLOG *g)
_SLOG_FUNC SLOGBUFGetLogBuffer (SLOG *g)
_SLOG_FUNC SLOGBUFGetHexLogBuffer (SLOG *g)
_SLOG_FUNC void CleanLogBuffer (SLOG *g, SLOGBUF *logbuf)
_SLOG_FUNC long FormatLogBuffer (SLOG *g, SLOGBUF *logbuf, const char *format,...)
_SLOG_FUNC long FormatLogBufferV (SLOG *g, SLOGBUF *logbuf, const char *format, va_list valist)
_SLOG_FUNC long MemcatLogBuffer (SLOG *g, SLOGBUF *logbuf, char *append, long len)
_SLOG_FUNC int ConvertLogOutput_atoi (char *output_desc)
 slog_apis_style_cover
_SLOG_FUNC int ConvertLogLevel_atoi (char *log_level_desc)
_SLOG_FUNC int ConvertLogLevels_atoi (char log_level_desc)
_SLOG_FUNC const char * ConvertLogLevel_itoa (int log_level)
_SLOG_FUNC const char ConvertLogLevels_itoa (int log_level)
_SLOG_FUNC long ConvertLogStyle_atol (char *line_style_desc)
_SLOG_FUNC long ConvertLogOption_atol (char *log_option_desc)
_SLOG_FUNC int ConvertLogRotateMode_atoi (char *rotate_mode_desc)
_SLOG_FUNC long ConvertBufferSize_atol (char *bufsize_desc)
_SLOG_FUNC int ExpandPathFilename (char *pathfilename, long pathfilename_bufsize)
 slog_apis_style_cover

Detailed Description

日志接口

Author
SUN
Date
2025-07-06
Version
1.0