|
@@ -19,6 +19,12 @@
|
19
|
19
|
/** A logger suitable for a shell
|
20
|
20
|
*
|
21
|
21
|
* Collect messages and deliver them when needed
|
|
22
|
+ *
|
|
23
|
+ * @warning This module is totally overkill. Most of the features (log collection
|
|
24
|
+ * etc.) seems to be useless ! Apparently, in a shell, we just want errors to be printed
|
|
25
|
+ * on stderr ?
|
|
26
|
+ *
|
|
27
|
+ * TODO continue to simplify the module & implement direct logging features
|
22
|
28
|
*/
|
23
|
29
|
|
24
|
30
|
#include <errno.h>
|
|
@@ -49,10 +55,14 @@
|
49
|
55
|
typedef struct asmsh_logger_s asmsh_logger_t;
|
50
|
56
|
typedef struct asmsh_log_msg_s asmsh_log_msg_t;
|
51
|
57
|
typedef enum asmsh_loglevel_e asmsh_loglevel_t;
|
|
58
|
+/**@param asmsh_log_msg_t* the log message to format
|
|
59
|
+ * @param char* the result buffer
|
|
60
|
+ * @param int the buffer size
|
|
61
|
+ * @return The needed size for the message in buffer (@see snprintf)
|
|
62
|
+ * if no error, else -1
|
|
63
|
+ */
|
52
|
64
|
typedef int (asmsh_log_fmt_f)(asmsh_log_msg_t*, char*, int);
|
53
|
65
|
|
54
|
|
-extern asmsh_logger_t *_default_logger;
|
55
|
|
-
|
56
|
66
|
|
57
|
67
|
enum asmsh_loglevel_e
|
58
|
68
|
{
|
|
@@ -64,6 +74,8 @@ enum asmsh_loglevel_e
|
64
|
74
|
ASMSH_FATAL = 50
|
65
|
75
|
};
|
66
|
76
|
|
|
77
|
+extern asmsh_logger_t *_default_logger;
|
|
78
|
+
|
67
|
79
|
|
68
|
80
|
struct asmsh_log_msg_s
|
69
|
81
|
{
|
|
@@ -78,6 +90,8 @@ struct asmsh_log_msg_s
|
78
|
90
|
struct asmsh_logger_s
|
79
|
91
|
{
|
80
|
92
|
asmsh_loglevel_t min_level;
|
|
93
|
+ /** Direct log fd */
|
|
94
|
+ //int dlog_fd; // TODO should be multiple FDs !?
|
81
|
95
|
/** Buffered messages
|
82
|
96
|
*
|
83
|
97
|
* A single buffer is used to store asmsh_log_msg_t and the
|
|
@@ -93,6 +107,8 @@ struct asmsh_logger_s
|
93
|
107
|
size_t msgs_alloc;
|
94
|
108
|
/** Default formatter */
|
95
|
109
|
asmsh_log_fmt_f *fmt;
|
|
110
|
+ /** Default direct log formatter */
|
|
111
|
+ asmsh_log_fmt_f *dfmt;
|
96
|
112
|
};
|
97
|
113
|
|
98
|
114
|
|
|
@@ -112,8 +128,13 @@ static inline int asmsh_logger_empty(asmsh_logger_t *logger) {
|
112
|
128
|
*/
|
113
|
129
|
int asmsh_logger_setup(asmsh_logger_t *logger);
|
114
|
130
|
|
|
131
|
+/** Returns a pointer on a newly allocated logger
|
|
132
|
+ * @param asmsh_log_level_t The minimum level for a message must have to be printed
|
|
133
|
+ * @returns A newly allocated logger that must be freed after use by @ref asmsh_logger_ferr()
|
|
134
|
+ */
|
115
|
135
|
asmsh_logger_t* asmsh_logger_new(asmsh_loglevel_t min_level);
|
116
|
136
|
|
|
137
|
+/** Free a logger */
|
117
|
138
|
void asmsh_logger_free(asmsh_logger_t* logger);
|
118
|
139
|
|
119
|
140
|
int asmsh_logger_dprint_fmt(int fd, asmsh_logger_t *logger, asmsh_log_fmt_f *custom_fmt);
|
|
@@ -128,10 +149,11 @@ static inline int asmsh_logger_stderr(asmsh_logger_t *logger) {
|
128
|
149
|
return asmsh_logger_dprint(2, logger);
|
129
|
150
|
}
|
130
|
151
|
|
131
|
|
-
|
|
152
|
+/** Log a message( see macros ) */
|
132
|
153
|
int asmsh_log(asmsh_logger_t *logger, asmsh_loglevel_t lvl, const char caller[], const char *msg, ...);
|
133
|
154
|
|
134
|
155
|
|
|
156
|
+/** Return a pointer on a static string representing a loglevel name */
|
135
|
157
|
const char * asmsh_loglevel_name(asmsh_loglevel_t lvl);
|
136
|
158
|
|
137
|
159
|
/** Default formatter with UTC datetime, lvl, caller and message */
|