ucx/logging.h

changeset 17
11dffb40cd91
parent 5
88625853ae74
child 70
88092b88ec00
equal deleted inserted replaced
16:5dbef9e07376 17:11dffb40cd91
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 *
145 * 158 *
146 * Dependent on the UcxLogger.mask some information is prepended. The complete 159 * Dependent on the UcxLogger.mask some information is prepended. The complete
147 * format is: 160 * format is:
148 * 161 *
149 * <code>[LEVEL] [TIMESTAMP] [SOURCEFILE]:[LINENO] message</code> 162 * <code>[LEVEL] [TIMESTAMP] [SOURCEFILE]:[LINENO] message</code>
163 *
164 * <b>Attention:</b> the message (including automatically generated information)
165 * <b>MUST NOT</b> exceed the size of 4 KB.
150 * 166 *
151 * @param logger the logger to use 167 * @param logger the logger to use
152 * @param level the level to log on 168 * @param level the level to log on
153 * @param file information about the source file 169 * @param file information about the source file
154 * @param line information about the source line number 170 * @param line information about the source line number
175 * @param ... format string and arguments 191 * @param ... format string and arguments
176 * @see ucx_logger_logf() 192 * @see ucx_logger_logf()
177 */ 193 */
178 #define ucx_logger_error(logger, ...) \ 194 #define ucx_logger_error(logger, ...) \
179 ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__) 195 ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__)
196
180 /** 197 /**
181 * Shortcut for logging an information message. 198 * Shortcut for logging an information message.
182 * @param logger the logger to use 199 * @param logger the logger to use
183 * @param ... format string and arguments 200 * @param ... format string and arguments
184 * @see ucx_logger_logf() 201 * @see ucx_logger_logf()
185 */ 202 */
186 #define ucx_logger_info(logger, ...) \ 203 #define ucx_logger_info(logger, ...) \
187 ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__) 204 ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__)
205
188 /** 206 /**
189 * Shortcut for logging a warning message. 207 * Shortcut for logging a warning message.
190 * @param logger the logger to use 208 * @param logger the logger to use
191 * @param ... format string and arguments 209 * @param ... format string and arguments
192 * @see ucx_logger_logf() 210 * @see ucx_logger_logf()
193 */ 211 */
194 #define ucx_logger_warn(logger, ...) \ 212 #define ucx_logger_warn(logger, ...) \
195 ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__) 213 ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__)
214
196 /** 215 /**
197 * Shortcut for logging a debug message. 216 * Shortcut for logging a debug message.
198 * @param logger the logger to use 217 * @param logger the logger to use
199 * @param ... format string and arguments 218 * @param ... format string and arguments
200 * @see ucx_logger_logf() 219 * @see ucx_logger_logf()
201 */ 220 */
202 #define ucx_logger_debug(logger, ...) \ 221 #define ucx_logger_debug(logger, ...) \
203 ucx_logger_log(logger, UCX_LOGGER_DEBUG, __VA_ARGS__) 222 ucx_logger_log(logger, UCX_LOGGER_DEBUG, __VA_ARGS__)
223
204 /** 224 /**
205 * Shortcut for logging a trace message. 225 * Shortcut for logging a trace message.
206 * @param logger the logger to use 226 * @param logger the logger to use
207 * @param ... format string and arguments 227 * @param ... format string and arguments
208 * @see ucx_logger_logf() 228 * @see ucx_logger_logf()

mercurial