-
Notifications
You must be signed in to change notification settings - Fork 7
/
bs_log.h
98 lines (80 loc) · 2.76 KB
/
bs_log.h
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
/**
* file : bs_log.h
* author : bushaofeng
* create : 2011.8.27
* func: 日志
* history: 2011.8.27 初始化
* 2013.11.19 加锁
*/
#ifndef __BS_LOG_H_
#define __BS_LOG_H_
#include <stdio.h>
#include "bs_type.h"
#ifdef __ANDROID__
#include <android/log.h>
#else
#include <sys/syslog.h>
#endif
#include "bs_def.h"
#include "bs_error.h"
#include "bs_lock.h"
#ifdef __cplusplus
extern "C"{
#endif
#ifdef __ANDROID__
#define LOG_EMERG ANDROID_LOG_SILENT/* system is unusable */
#define LOG_ALERT ANDROID_LOG_FATAL/* action must be taken immediately */
#define LOG_CRIT ANDROID_LOG_DEFAULT/* critical conditions */
#define LOG_ERR ANDROID_LOG_ERROR/* error conditions */
#define LOG_WARNING ANDROID_LOG_WARN/* warning conditions */
#define LOG_NOTICE ANDROID_LOG_VERBOSE/* normal but significant condition */
#define LOG_INFO ANDROID_LOG_INFO/* informational */
#define LOG_DEBUG ANDROID_LOG_DEBUG
#else
#define LOG_EMERG 0/* system is unusable */
#define LOG_ALERT 1/* action must be taken immediately */
#define LOG_CRIT 2/* critical conditions */
#define LOG_ERR 3/* error conditions */
#define LOG_WARNING 4/* warning conditions */
#define LOG_NOTICE 5/* normal but significant condition */
#define LOG_INFO 6/* informational */
#define LOG_DEBUG 7/* debug-level messages */
#endif
#define LOG_NUM 8
#ifdef __ANDROID__
#define err_log(log, args...) __android_log_print(LOG_ERR, "Visionin", log, ##args);
#define warn_log(log, args...) __android_log_print(LOG_WARNING, "Visionin", log, ##args);
#define info_log(log, args...) __android_log_print(LOG_INFO, "Visionin", log, ##args);
#define debug_log(log, args...) __android_log_print(LOG_DEBUG, "Visionin", log, ##args);
#else
#define err_log(log, args...) bs_log(g_log, LOG_ERR, log, ##args);
#define warn_log(log, args...) bs_log(g_log, LOG_WARNING, log, ##args);
#define info_log(log, args...) bs_log(g_log, LOG_INFO, log, ##args);
#define debug_log(log, args...) do{ \
char buf[BS_DEF_STRLEN]; \
sprintf(buf, log, ##args); \
bs_log(g_log, LOG_DEBUG, "%s: %s", __FUNCTION__, buf); \
}while(0)
#endif
typedef struct{
char path[BS_DEF_STRLEN];
FILE* type_file[LOG_NUM];
FILE* file;
int flag[LOG_NUM];
struct tm ltm;
bs_lock_t lock;
}bs_log_t;
extern bs_log_t* g_log;
int bs_log_type(const char* name);
// 默认开启fatal日志
state_t bs_log_init(const char* path);
state_t bs_log_init_entity(bs_log_t* plog, const char* path);
state_t bs_log_set(bs_log_t* plog, int log, int flag);
state_t bs_log_setflag(bs_log_t* plog, const int* flag, uint32_t size);
state_t bs_log_close(bs_log_t* plog);
state_t bs_log(bs_log_t* plog, int log, const char fmt[], ...);
state_t bs_log_destroy();
#ifdef __cplusplus
}
#endif
#endif