42 #ifdef __cplusplus |
42 #ifdef __cplusplus |
43 extern "C" { |
43 extern "C" { |
44 #endif |
44 #endif |
45 |
45 |
46 /* leave enough space for custom log levels */ |
46 /* leave enough space for custom log levels */ |
|
47 |
47 /** Log level for error messages. */ |
48 /** Log level for error messages. */ |
48 #define UCX_LOGGER_ERROR 0x00 |
49 #define UCX_LOGGER_ERROR 0x00 |
|
50 |
49 /** Log level for warning messages. */ |
51 /** Log level for warning messages. */ |
50 #define UCX_LOGGER_WARN 0x10 |
52 #define UCX_LOGGER_WARN 0x10 |
|
53 |
51 /** Log level for information messages. */ |
54 /** Log level for information messages. */ |
52 #define UCX_LOGGER_INFO 0x20 |
55 #define UCX_LOGGER_INFO 0x20 |
|
56 |
53 /** Log level for debug messages. */ |
57 /** Log level for debug messages. */ |
54 #define UCX_LOGGER_DEBUG 0x30 |
58 #define UCX_LOGGER_DEBUG 0x30 |
|
59 |
55 /** Log level for trace messages. */ |
60 /** Log level for trace messages. */ |
56 #define UCX_LOGGER_TRACE 0x40 |
61 #define UCX_LOGGER_TRACE 0x40 |
57 |
62 |
58 /** |
63 /** |
59 * Output flag for the log level. |
64 * Output flag for the log level. |
60 * If this flag is set, the log message will contain the log level. |
65 * If this flag is set, the log message will contain the log level. |
61 * @see UcxLogger.mask |
66 * @see UcxLogger.mask |
62 */ |
67 */ |
63 #define UCX_LOGGER_LEVEL 0x01 |
68 #define UCX_LOGGER_LEVEL 0x01 |
|
69 |
64 /** |
70 /** |
65 * Output flag for the timestmap. |
71 * Output flag for the timestmap. |
66 * If this flag is set, the log message will contain the timestmap. |
72 * If this flag is set, the log message will contain the timestmap. |
67 * @see UcxLogger.mask |
73 * @see UcxLogger.mask |
68 */ |
74 */ |
69 #define UCX_LOGGER_TIMESTAMP 0x02 |
75 #define UCX_LOGGER_TIMESTAMP 0x02 |
|
76 |
70 /** |
77 /** |
71 * Output flag for the source. |
78 * Output flag for the source. |
72 * If this flag is set, the log message will contain the source file and line |
79 * If this flag is set, the log message will contain the source file and line |
73 * number. |
80 * number. |
74 * @see UcxLogger.mask |
81 * @see UcxLogger.mask |
79 * The UCX Logger object. |
86 * The UCX Logger object. |
80 */ |
87 */ |
81 typedef struct { |
88 typedef struct { |
82 /** The stream this logger writes its messages to.*/ |
89 /** The stream this logger writes its messages to.*/ |
83 void *stream; |
90 void *stream; |
|
91 |
84 /** |
92 /** |
85 * The write function that shall be used. |
93 * The write function that shall be used. |
86 * For standard file or stdout loggers this might be standard fwrite |
94 * For standard file or stdout loggers this might be standard fwrite |
87 * (default). |
95 * (default). |
88 */ |
96 */ |
89 write_func writer; |
97 write_func writer; |
|
98 |
90 /** |
99 /** |
91 * The date format for timestamp outputs |
100 * The date format for timestamp outputs |
92 * (default: <code>"%F %T %z "</code>). |
101 * (default: <code>"%F %T %z "</code>). |
93 * @see UCX_LOGGER_TIMESTAMP |
102 * @see UCX_LOGGER_TIMESTAMP |
94 */ |
103 */ |
95 char *dateformat; |
104 char *dateformat; |
|
105 |
96 /** |
106 /** |
97 * The level, this logger operates on. |
107 * The level, this logger operates on. |
98 * If a log command is issued, the message will only be logged, if the log |
108 * If a log command is issued, the message will only be logged, if the log |
99 * level of the message is less or equal than the log level of the logger. |
109 * level of the message is less or equal than the log level of the logger. |
100 */ |
110 */ |
101 unsigned int level; |
111 unsigned int level; |
|
112 |
102 /** |
113 /** |
103 * A configuration mask for automatic output. |
114 * A configuration mask for automatic output. |
104 * For each flag that is set, the logger automatically outputs some extra |
115 * For each flag that is set, the logger automatically outputs some extra |
105 * information like the timestamp or the source file and line number. |
116 * information like the timestamp or the source file and line number. |
106 * See the documentation for the flags for details. |
117 * See the documentation for the flags for details. |
107 */ |
118 */ |
108 unsigned int mask; |
119 unsigned int mask; |
|
120 |
109 /** |
121 /** |
110 * A map of valid log levels for this logger. |
122 * A map of valid log levels for this logger. |
111 * |
123 * |
112 * The keys represent all valid log levels and the values provide string |
124 * The keys represent all valid log levels and the values provide string |
113 * representations, that are used, if the UCX_LOGGER_LEVEL flag is set. |
125 * representations, that are used, if the UCX_LOGGER_LEVEL flag is set. |
126 * @param level the level on which the logger shall operate |
138 * @param level the level on which the logger shall operate |
127 * @param mask configuration mask (cf. UcxLogger.mask) |
139 * @param mask configuration mask (cf. UcxLogger.mask) |
128 * @return a new logger object |
140 * @return a new logger object |
129 */ |
141 */ |
130 UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask); |
142 UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask); |
|
143 |
131 /** |
144 /** |
132 * Destroys the logger. |
145 * Destroys the logger. |
133 * |
146 * |
134 * The map containing the valid log levels is also automatically destroyed. |
147 * The map containing the valid log levels is also automatically destroyed. |
135 * |
148 * |
178 * @param ... format string and arguments |
191 * @param ... format string and arguments |
179 * @see ucx_logger_logf() |
192 * @see ucx_logger_logf() |
180 */ |
193 */ |
181 #define ucx_logger_error(logger, ...) \ |
194 #define ucx_logger_error(logger, ...) \ |
182 ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__) |
195 ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__) |
|
196 |
183 /** |
197 /** |
184 * Shortcut for logging an information message. |
198 * Shortcut for logging an information message. |
185 * @param logger the logger to use |
199 * @param logger the logger to use |
186 * @param ... format string and arguments |
200 * @param ... format string and arguments |
187 * @see ucx_logger_logf() |
201 * @see ucx_logger_logf() |
188 */ |
202 */ |
189 #define ucx_logger_info(logger, ...) \ |
203 #define ucx_logger_info(logger, ...) \ |
190 ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__) |
204 ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__) |
|
205 |
191 /** |
206 /** |
192 * Shortcut for logging a warning message. |
207 * Shortcut for logging a warning message. |
193 * @param logger the logger to use |
208 * @param logger the logger to use |
194 * @param ... format string and arguments |
209 * @param ... format string and arguments |
195 * @see ucx_logger_logf() |
210 * @see ucx_logger_logf() |
196 */ |
211 */ |
197 #define ucx_logger_warn(logger, ...) \ |
212 #define ucx_logger_warn(logger, ...) \ |
198 ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__) |
213 ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__) |
|
214 |
199 /** |
215 /** |
200 * Shortcut for logging a debug message. |
216 * Shortcut for logging a debug message. |
201 * @param logger the logger to use |
217 * @param logger the logger to use |
202 * @param ... format string and arguments |
218 * @param ... format string and arguments |
203 * @see ucx_logger_logf() |
219 * @see ucx_logger_logf() |
204 */ |
220 */ |
205 #define ucx_logger_debug(logger, ...) \ |
221 #define ucx_logger_debug(logger, ...) \ |
206 ucx_logger_log(logger, UCX_LOGGER_DEBUG, __VA_ARGS__) |
222 ucx_logger_log(logger, UCX_LOGGER_DEBUG, __VA_ARGS__) |
|
223 |
207 /** |
224 /** |
208 * Shortcut for logging a trace message. |
225 * Shortcut for logging a trace message. |
209 * @param logger the logger to use |
226 * @param logger the logger to use |
210 * @param ... format string and arguments |
227 * @param ... format string and arguments |
211 * @see ucx_logger_logf() |
228 * @see ucx_logger_logf() |