-
Notifications
You must be signed in to change notification settings - Fork 7
/
slog.h
150 lines (122 loc) · 4.08 KB
/
slog.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* The MIT License (MIT)
*
* Copyleft (C) 2015 Sun Dro (a.k.a. kala13x)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*/
#ifndef __SLOG_H__
#define __SLOG_H__
/* For include header in CPP code */
#ifdef __cplusplus
extern "C" {
#endif
#include <pthread.h>
/* Definations for version info */
#define SLOGVERSION_MAX 1
#define SLOGVERSION_MIN 4
#define SLOGBUILD_NUM 82
/* Defined app logging levels */
#define LOG_NONE 0
#define LOG_PANIC 1
#define LOG_FATAL 2
#define LOG_ERROR 3
#define LOG_WARN 4
#define LOG_INFO 5
#define LOG_DEBUG 6
#define LOG_LIVE 7
#define LOG_EXTRA 8
/* Loging flags */
#define SLOG_NONE 0
#define SLOG_LIVE 1
#define SLOG_INFO 2
#define SLOG_WARN 3
#define SLOG_DEBUG 4
#define SLOG_ERROR 5
#define SLOG_FATAL 6
#define SLOG_PANIC 7
/* Supported colors */
#define CLR_NORMAL "\x1B[0m"
#define CLR_RED "\x1B[31m"
#define CLR_GREEN "\x1B[32m"
#define CLR_YELLOW "\x1B[33m"
#define CLR_BLUE "\x1B[34m"
#define CLR_NAGENTA "\x1B[35m"
#define CLR_CYAN "\x1B[36m"
#define CLR_WHITE "\x1B[37m"
#define CLR_RESET "\033[0m"
/* Flags */
typedef struct {
const char* fname;
short file_level;
short level;
short to_file;
short pretty;
short filestamp;
short td_safe;
} SlogFlags;
/* Date variables */
typedef struct {
int year;
int mon;
int day;
int hour;
int min;
int sec;
int usec;
} SlogDate;
/*
* Get library version. Function returns version and build number of slog
* library. Return value is char pointer. Argument min is flag for output
* format. If min is 1, function returns version in full format, if flag
* is 0 function returns only version numbers, For examle: 1.0.52.
-*/
const char* slog_version(int min);
/*
* strclr - Colorize string. Function takes color value and string
* and returns colorized string as char pointer. First argument clr
* is color value (if it is invalid, function retunrs NULL) and second
* is string with va_list of arguments which one we want to colorize.
*/
char* strclr(const char* clr, char* str, ...);
/*
* Return string in slog format. Function takes arguments
* and returns string in slog format without printing and
* saveing in file. Return value is char pointer.
*/
char* slog_get(SlogDate *pDate, char *msg, ...);
/*
* slog - Log exiting process. Function takes arguments and saves
* log in file if LOGTOFILE flag is enabled from config. Otherwise
* it just prints log without saveing in file. Argument level is
* logging level and flag is slog flags defined in slog.h header.
*/
void slog(int level, int flag, const char *msg, ...);
/*
* Initialize slog library. Function parses config file and reads log
* level and save to file flag from config. First argument is file name
* where log will be saved and second argument conf is config file path
* to be parsed and third argument lvl is log level for this message.
*/
void slog_init(const char* fname, const char* conf, int lvl, int flvl, int t_safe);
/* For include header in CPP code */
#ifdef __cplusplus
}
#endif
#endif /* __SLOG_H__ */