forked from ronkashi/SP-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPLogger.h
217 lines (207 loc) · 8.53 KB
/
SPLogger.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#ifndef SPLOGGER_H_
#define SPLOGGER_H_
/**
* SP Logger summary:
* SP Logger is defined at compilation time and it must be initialized
* by calling the create function prior to the usage.
*
* The logger has 4 print levels:
* - Error level: In this level only error messages are printed
* - Warning level: In this level only warning and error messages are printed
* - Info level: in this level info, warning and error messages are printed
* - Debug level: in this level all message are printed
*
* The logger supports another printing function which can be called at any level
* The user must destroy the logger at end of usage
*
* The following functions are supported:
* spLoggerCreate - Creates and initializes the logger
* spLoggerDestroy - Closes are frees all resources of the logger
* spLoggerPrintError - Prints error messages at leves {Error, Warning, Info, Debug}
* spLoggerPrintWarning - Prints warnning messages at levels {Warning, Info, Debug}
* spLoggerPrintInfo - Prints info messages at levels {Info, Debug}
* spLoggerPrintDebug - Prints debug messages at level {Debug}
* spLoggerPrintMsg - Prints the exact message at any level (Without formatting)
*/
/** A type used to decide the level of the logger**/
typedef enum sp_logger_level_t {
SP_LOGGER_ERROR_LEVEL, //Error level
SP_LOGGER_WARNING_ERROR_LEVEL, //Warning level
SP_LOGGER_INFO_WARNING_ERROR_LEVEL, //Info level
SP_LOGGER_DEBUG_INFO_WARNING_ERROR_LEVEL //Debug level
} SP_LOGGER_LEVEL;
/** A type used to indicate errors in function calls **/
typedef enum sp_logger_msg_t {
SP_LOGGER_CANNOT_OPEN_FILE,
SP_LOGGER_INVAlID_ARGUMENT,
SP_LOGGER_OUT_OF_MEMORY,
SP_LOGGER_UNDIFINED,
SP_LOGGER_DEFINED,
SP_LOGGER_WRITE_FAIL,
SP_LOGGER_SUCCESS
} SP_LOGGER_MSG;
/** A type used for defining the logger**/
typedef struct sp_logger_t* SPLogger;
/**
* Creates a logger. This function should be called once, prior
* to the usage of any SP Logger print functions. It is the responsibility
* of the user to create the logger prior to usage, and the logger
* must be destroyed at the end of usage.
*
* @param filename - The name of the log file, if not specified stdout is used
* as default.
* @param level - The level of the logger prints
* @return
* SP_LOGGER_DEFINED - The logger has been defined
* SP_LOGGER_OUT_OF_MEMORY - In case of memory allocation failure
* SP_LOGGER_CANNOT_OPEN_FILE - If the file given by filename cannot be opened
* SP_LOGGER_SUCCESS - In case the logger has been successfully opened
*/
SP_LOGGER_MSG spLoggerCreate(const char* filename, SP_LOGGER_LEVEL level);
/**
* Frees all memory allocated for the logger. If the logger is not defined
* then nothing happens.
*/
void spLoggerDestroy();
/**
* Prints error message. The error message format is given below:
* ---ERROR---
* - file: <file>
* - function: <function>
* - line: <line>
* - message: <msg>
*
* <file> - is the string given by file, it represents the file in which
* the error print call occurred.
* <function> - is the string given by function, it represents the function in which
* the error print call occurred.
* <line> - is the string given by line, it represents the line in which
* the error print call occurred
* <msg> - is the string given by msg, it contains the msg given by the user
*
* Error messages will be printed at levels:
*
* SP_LOGGER_ERROR_LEVEL,
* SP_LOGGER_WARNING_ERROR_LEVEL,
* SP_LOGGER_INFO_WARNING_ERROR_LEVEL,
* SP_LOGGER_DEBUG_INFO_WARNING_ERROR_LEVEL
*
* A new line will be printed after the print call.
*
* @param msg - The message to printed
* @param file - A string representing the filename in which spLoggerPrintError call occurred
* @param function - A string representing the function name in which spLoggerPrintError call ocurred
* @param line - A string representing the line in which the function call occurred
* @return
* SP_LOGGER_UNDIFINED - If the logger is undefined
* SP_LOGGER_INVAlID_ARGUMENT - If any of msg or file or function are null or line is negative
* SP_LOGGER_WRITE_FAIL - If Write failure occurred
* SP_LOGGER_SUCCESS - otherwise
*/
SP_LOGGER_MSG spLoggerPrintError(const char* msg, const char* file,
const char* function, const int line);
/**
* Prints warning message. The warning message format is given below:
* ---WARNING---
* - file: <file>
* - function: <function>
* - line: <line>
* - message: <msg>
*
* <file> - is the string given by file, it represents the file in which
* the warning print call occurred.
* <function> - is the string given by function, it represents the function in which
* the warning print call occurred.
* <line> - is the string given by line, it represents the line in which
* the warning print call occurred
* <msg> - is the string given by msg, it contains the msg given by the user
*
* Warning messages will be printed at levels:
*
* SP_LOGGER_WARNING_ERROR_LEVEL,
* SP_LOGGER_INFO_WARNING_ERROR_LEVEL,
* SP_LOGGER_DEBUG_INFO_WARNING_ERROR_LEVEL
*
* A new line will be printed after the print call.
*
* @param msg - The message to printed
* @param file - A string representing the filename in which spLoggerPrintWarning call occurred
* @param function - A string representing the function name in which spLoggerPrintWarning call ocurred
* @param line - A string representing the line in which the spLoggerPrintWarning call occurred
* @return
* SP_LOGGER_UNDIFINED - If the logger is undefined
* SP_LOGGER_INVAlID_ARGUMENT - If any of msg or file or function are null or line is negative
* SP_LOGGER_WRITE_FAIL - If write failure occurred
* SP_LOGGER_SUCCESS - otherwise
*/
SP_LOGGER_MSG spLoggerPrintWarning(const char* msg, const char* file,
const char* function, const int line);
/**
* Prints Info message. The info message format is given below:
* ---INFO---
* - message: <msg>
*
* <msg> - is the string given by msg, it contains the msg given by the user
*
* Info messages will be printed at levels:
*
* SP_LOGGER_INFO_WARNING_ERROR_LEVEL,
* SP_LOGGER_DEBUG_INFO_WARNING_ERROR_LEVEL
*
* A new line will be printed after the print call.
*
* @param msg - The message to printed
* @return
* SP_LOGGER_UNDIFINED - If the logger is undefined
* SP_LOGGER_INVAlID_ARGUMENT - If msg is null
* SP_LOGGER_WRITE_FAIL - If Write failure occurred
* SP_LOGGER_SUCCESS - otherwise
*/
SP_LOGGER_MSG spLoggerPrintInfo(const char* msg);
/**
* Prints the debug message. The debug message format is given below:
* ---DEBUG---
* - file: <file>
* - function: <function>
* - line: <line>
* - message: <msg>
*
* <file> - is the string given by file, it represents the file in which
* the debug print call occurred.
* <function> - is the string given by function, it represents the function in which
* the debug print call occurred.
* <line> - is the string given by line, it represents the line in which
* the debug print call occurred
* <msg> - is the string given by msg, it contains the msg given by the user
*
* Debug messages will be printed at level:
*
* SP_LOGGER_DEBUG_INFO_WARNING_ERROR_LEVEL
*
* A new line will be printed after the print call.
*
* @param msg - The message to printed
* @param file - A string representing the filename in which spLoggerPrintWarning call occurred
* @param function - A string representing the function name in which spLoggerPrintWarning call ocurred
* @param line - A string representing the line in which the function call occurred
* @return
* SP_LOGGER_UNDIFINED - If the logger is undefined
* SP_LOGGER_INVAlID_ARGUMENT - If any of msg or file or function are null or line is negative
* SP_LOGGER_WRITE_FAIL - If Write failure occurred
* SP_LOGGER_SUCCESS - otherwise
*/
SP_LOGGER_MSG spLoggerPrintDebug(const char* msg, const char* file,
const char* function, const int line);
/**
* The given message is printed. A new line is printed at the end of msg
* The message will be printed in all levels.
*
* @param msg - The message to be printed
* @return
* SP_LOGGER_UNDIFINED - If the logger is undefined
* SP_LOGGER_INVAlID_ARGUMENT - If msg is null
* SP_LOGGER_WRITE_FAIL - If Write failure occurred
* SP_LOGGER_SUCCESS - otherwise
*/
SP_LOGGER_MSG spLoggerPrintMsg(const char* msg);
#endif