commit | author | age
|
13d8a8
|
1 |
/********************************************************************************* |
G |
2 |
* Copyright: (C) 2023 LingYun IoT System Studio. |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* Filename: logger.h |
|
6 |
* Description: This file is common logger API functions |
29b331
|
7 |
* |
13d8a8
|
8 |
* Version: 1.0.0(11/08/23) |
G |
9 |
* Author: Guo Wenxue <guowenxue@gmail.com> |
|
10 |
* ChangeLog: 1, Release initial version on "11/08/23 16:18:43" |
29b331
|
11 |
* |
13d8a8
|
12 |
********************************************************************************/ |
G |
13 |
|
|
14 |
#ifndef _LOGGER_H_ |
|
15 |
#define _LOGGER_H_ |
|
16 |
|
|
17 |
#include <stdio.h> |
|
18 |
#include <stdarg.h> |
|
19 |
|
|
20 |
#define LOG_VERSION "v0.1" |
|
21 |
|
|
22 |
/* log level */ |
|
23 |
enum { |
|
24 |
LOG_LEVEL_ERROR, |
|
25 |
LOG_LEVEL_WARN, |
|
26 |
LOG_LEVEL_INFO, |
|
27 |
LOG_LEVEL_DEBUG, |
|
28 |
LOG_LEVEL_TRACE, |
|
29 |
LOG_LEVEL_MAX |
|
30 |
}; |
|
31 |
|
|
32 |
enum { |
|
33 |
LOG_LOCK_DISABLE, /* disable lock */ |
|
34 |
LOG_LOCK_ENABLE, /* enable lock */ |
|
35 |
}; |
|
36 |
|
|
37 |
#define ROLLBACK_NONE 0 |
|
38 |
|
|
39 |
/* description: Initial the logger system |
|
40 |
* arguments : |
|
41 |
* $fname: logger file name, NULL/"console"/"stderr" will log to console |
|
42 |
* $level: logger level above; |
|
43 |
* $size : logger file max size in KiB |
|
44 |
* $lock : thread lock enable or not |
|
45 |
* return : <0: Failed ==0: Sucessfully |
|
46 |
*/ |
|
47 |
#define THREAD_LOCK_NONE 0 |
|
48 |
#define THREAD_LOCK_EN 1 |
|
49 |
int log_open(char *fname, int level, int size, int lock); |
|
50 |
|
|
51 |
|
|
52 |
/* description: Terminate the logger system */ |
|
53 |
void log_close(void); |
|
54 |
|
|
55 |
|
|
56 |
/* description: log message into log file. Don't call this function directly. */ |
|
57 |
void _log_write(int level, const char *file, int line, const char *fmt, ...); |
|
58 |
|
|
59 |
|
|
60 |
/* description: dump a buffer in hex to logger file */ |
|
61 |
void log_dump(int level, const char *prompt, char *buf, size_t len); |
|
62 |
|
|
63 |
/* function: log message into logger file with different log level */ |
|
64 |
#define log_trace(...) _log_write(LOG_LEVEL_TRACE, __FILE__, __LINE__, __VA_ARGS__) |
|
65 |
#define log_debug(...) _log_write(LOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__) |
|
66 |
#define log_info(...) _log_write(LOG_LEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__) |
|
67 |
#define log_warn(...) _log_write(LOG_LEVEL_WARN, __FILE__, __LINE__, __VA_ARGS__) |
|
68 |
#define log_error(...) _log_write(LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__) |
|
69 |
|
|
70 |
#endif |