1 /*------------------------------------------------------------------------------
2  *
3  * Copyright (c) 2011-2021, EURid vzw. All rights reserved.
4  * The YADIFA TM software product is provided under the BSD 3-clause license:
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *        * Redistributions in binary form must reproduce the above copyright
13  *          notice, this list of conditions and the following disclaimer in the
14  *          documentation and/or other materials provided with the distribution.
15  *        * Neither the name of EURid nor the names of its contributors may be
16  *          used to endorse or promote products derived from this software
17  *          without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  *------------------------------------------------------------------------------
32  *
33  */
34 
35 /** @defgroup logger Logging functions
36  *  @ingroup dnscore
37  *  @brief
38  *
39  *
40  *
41  * @{
42  *
43  *----------------------------------------------------------------------------*/
44 #ifndef _LOGGER_HANDLE_H
45 #define	_LOGGER_HANDLE_H
46 
47 #include <syslog.h>
48 #include <sys/socket.h>
49 
50 #define LOGGER_EARLY_CULL 1
51 
52 #include <dnscore/thread.h>
53 #include <dnscore/thread-tag.h>
54 #include <dnscore/ptr_vector.h>
55 #include <dnscore/format.h>
56 
57 /*
58  * Basically a copy from syslog
59  */
60 
61 #define MSG_EMERG      0   /* system is unusable                      */
62 #define MSG_ALERT      1   /* action must be taken immediately        */
63 #define MSG_CRIT       2   /* critical conditions                     */
64 #define MSG_ERR        3   /* error conditions                        */
65 #define MSG_WARNING    4   /* warning conditions                      */
66 #define MSG_NOTICE     5   /* normal, but significant, condition      */
67 #define MSG_INFO       6   /* informational message                   */
68 #define MSG_DEBUG      7   /* debug-level message                     */
69 #define MSG_DEBUG1     8   /* debug-level message                     */
70 #define MSG_DEBUG2     9   /* debug-level message                     */
71 #define MSG_DEBUG3     10  /* debug-level message                     */
72 #define MSG_DEBUG4     11  /* debug-level message                     */
73 #define MSG_DEBUG5     12  /* debug-level message                     */
74 #define MSG_DEBUG6     13  /* debug-level message                     */
75 #define MSG_DEBUG7     14  /* debug-level message                     */
76 
77 #define MSG_ALL        15   /* all message levels                     */
78 #define MSG_ALL_MASK   0xffff  /// all message levels as a bitmap
79 #define MSG_PROD_MASK  0x007f  /// non-debug message levels as a bitmap
80 #define MSG_WARN_MASK  0x001f  /// warnings and worse messages levels as a bitmap
81 
82 
83 #define MSG_LEVEL_COUNT 16
84 
85 /**
86  * The default buffer size (0-cost) made available for each line.
87  * If the line is bigger the buffer's size is raised at a certain (non-nul)
88  * cost.
89  *
90  */
91 
92 #define DEFAULT_MAX_LINE_SIZE	128
93 
94 #define LOG_QUEUE_MIN_SIZE              0x00000400              //  1K
95 #define LOG_QUEUE_MAX_SIZE              0x01000000              // 16M
96 #define LOG_QUEUE_DEFAULT_SIZE          0x00100000              //  1M
97 
98 #define HAS_SHARED_QUEUE_SUPPORT 1      // must be 1
99 
100 #ifdef	__cplusplus
101 extern "C"
102 {
103 #endif
104 
105 /**
106  * Handle
107  */
108 
109 typedef ptr_vector logger_channel_array;
110 
111 struct logger_channel;
112 
113 typedef struct logger_handle logger_handle;
114 
115 #if DEBUG
116 #define LOGGER_HANDLE_MAGIC_CHECK 0x11332244
117 #endif
118 
119 #define LOGGER_HANDLE_NAME_SIZE_MAX 16
120 #define LOGGER_HANDLE_FORMATTED_NAME_SIZE_MAX 8
121 
122 #define LOGGER_REPEAT_COMPRESSION 1
123 
124 struct logger_handle // ~ 5 * 64
125 {
126     u8 active[MSG_LEVEL_COUNT]; // 16 /// @note 20200818 edf -- I know what I always say about layout.  This is an exception.  Keep it first.
127     logger_channel_array channels[MSG_LEVEL_COUNT]; // 256
128     char name[LOGGER_HANDLE_NAME_SIZE_MAX]; // 16
129     char formatted_name[LOGGER_HANDLE_FORMATTED_NAME_SIZE_MAX + 1]; // 8 + 1
130     bool enabled; // 1
131     // I expect 6 padding bytes here
132     struct logger_handle **global_reference; // 8
133 #if DEBUG
134     u32 magic_check;
135 #endif
136 };
137 
138 #if LOGGER_EARLY_CULL
139 extern struct logger_handle LOGGER_HANDLE_SINK_;
140 #define LOGGER_HANDLE_SINK (&LOGGER_HANDLE_SINK_)
141 #else
142 #define LOGGER_HANDLE_SINK NULL
143 #endif
144 
145 /**
146  * Channel
147  */
148 
149 struct logger_channel_vtbl;
150 struct logger_message;
151 
152 struct logger_channel
153 {
154     void *data;
155     const struct logger_channel_vtbl *vtbl;
156 #if LOGGER_REPEAT_COMPRESSION
157     struct logger_message *last_message;
158     u32 last_message_count;
159 #endif
160     s32 linked_handles;
161 };
162 
163 typedef struct logger_channel logger_channel;
164 
165 typedef ya_result logger_channel_constmsg_method(logger_channel* chan, int level, char* text, u32 text_len, u32 date_offset);
166 typedef ya_result logger_channel_msg_method(logger_channel* chan, int level, char* text, ...);
167 typedef ya_result logger_channel_vmsg_method(logger_channel* chan, int level, char* text, va_list args);
168 typedef void logger_channel_flush_method(logger_channel* chan);
169 typedef void logger_channel_close_method(logger_channel* chan);
170 typedef ya_result logger_channel_reopen_method(logger_channel* chan);
171 typedef void logger_channel_sink_method(logger_channel* chan);
172 
173 typedef struct logger_channel_vtbl logger_channel_vtbl;
174 
175 struct logger_channel_vtbl
176 {
177     logger_channel_constmsg_method *constmsg;
178     logger_channel_msg_method *msg;
179     logger_channel_vmsg_method *vmsg;
180     logger_channel_flush_method *flush;
181     logger_channel_close_method *close;
182     logger_channel_reopen_method *reopen;   // so a HUP will flush, close then reopen/create the log files again
183     logger_channel_sink_method *sink;       // the channel will verify its output make sense and if not act on it (ie: junk all until next reopen)
184     const char *__class__;
185 };
186 
187 #define logger_channel_msg(channel_,level_,text_, text_len_, date_offs_) (channel_)->vtbl->constmsg((channel_),(level_),(text_),(text_len_),(date_offs_))
188 #define logger_channel_msgf(channel_,level_,text_, ...) (channel_)->vtbl->msg((channel_),(level_),(text_),__VA_ARGS__)
189 #define logger_channel_vmsgf(channel_,level_,text_, args_) (channel_)->vtbl->msg((channel_),(level_),(text_),(args_))
190 #define logger_channel_flush(channel_) (channel_)->vtbl->flush(channel_)
191 #define logger_channel_reopen(channel_) (channel_)->vtbl->reopen(channel_)
192 #define logger_channel_close(channel_) (channel_)->vtbl->close(channel_)
193 #define logger_channel_sink(channel_) (channel_)->vtbl->sink(channel_)
194 
195 /**
196  * Message flags
197  */
198 
199 #define LOGGER_MESSAGE_STD      0
200 #define LOGGER_MESSAGE_TIMEMS   1
201 #define LOGGER_MESSAGE_PREFIX   2
202 
203 /**
204  * Allocates an empty channel
205  * Meant to be used by channels implementation
206  */
207 
208 logger_channel* logger_channel_alloc();
209 
210 /**
211  * Returns true iff the current thread is the logger.
212  *
213  * @return true iff the current thread is the logger.
214  */
215 
216 bool logger_is_self();
217 
218 /**
219  * Returns TRUE if the queue is half full
220  *
221  * @param channel_name
222  * @return
223  */
224 
225 bool logger_queue_fill_critical();
226 
227 s32 logger_channel_get_usage_count(const char* channel_name);
228 void logger_channel_register(const char* channel_name, struct logger_channel *channel);
229 void logger_channel_unregister(const char* channel_name);
230 
231 void logger_channel_close_all();
232 
233 void logger_handle_create(const char *logger_name, logger_handle **handle_holder);
234 void logger_handle_add_channel(const char* logger_name, int level, const char* channel_name);
235 void logger_handle_remove_channel(const char *logger_name, const char *channel_name);
236 s32 logger_handle_count_channels(const char *logger_name);
237 void logger_handle_close(const char *logger_name);
238 
239 /**
240  *
241  * Helper function.
242  * Creates a logger for the given file descriptor (typically 1/stdout or 2/stderr)
243  *
244  * ie: logger_handle_create_to_fd("system", MSG_ALL_MASK, 1);
245  *
246  * @param logger_name name of the logger
247  * @param mask the mask to use (ie: MSG_ALL_MASK)
248  * @param fd the file descriptor
249  */
250 
251 void logger_handle_create_to_fd(const char *logger_name, int mask, int fd);
252 
logger_handle_create_to_stdout(const char * logger_name,int mask)253 static inline void logger_handle_create_to_stdout(const char *logger_name, int mask)
254 {
255     logger_handle_create_to_fd(logger_name, mask, 1);
256 }
257 
258 /**
259  *
260  * Sends a formatted text to the logger
261  *
262  * @param handle        handle to use, can be NULL
263  * @param level         level of the message
264  * @param fmt           format string
265  * @param args          parameters for the format
266  */
267 
268 void logger_handle_vmsg(logger_handle* handle, u32 level, const char* fmt, va_list args);
269 
270 /**
271  *
272  * Sends a formatted text to the logger
273  *
274  * @param handle        handle to use, can be NULL
275  * @param level         level of the message
276  * @param fmt           format string
277  * @param ...           parameters for the format
278  */
279 
280 void logger_handle_msg(logger_handle* handle, u32 level, const char* fmt, ...);
281 
282 void logger_handle_msg_nocull(logger_handle* handle, u32 level, const char* fmt, ...);
283 
284 /**
285  *
286  * Sends a text to the logger
287  *
288  * @param handle        handle to use, can be NULL
289  * @param level         level of the message
290  * @param text          text to send
291  * @param text_len      length of the text to send
292  */
293 
294 void logger_handle_msg_text(logger_handle *handle, u32 level, const char* text, u32 text_len);
295 
296 /**
297  *
298  * Sends a text to the logger with a prefix
299  *
300  * @param handle        handle to use, can be NULL
301  * @param level         level of the message
302  * @param text          text to send
303  * @param text_len      text length
304  * @param prefix        prefix
305  * @param prefix_len    prefix length
306  * @param flags         LOGGER_MESSAGE_* flags
307  */
308 
309 void logger_handle_msg_text_ext(logger_handle *handle, u32 level, const char* text, u32 text_len, const char* prefix, u32 prefix_len, u16 flags);
310 
311 /**
312  * Try to send a formatted text to the logger.
313  * If the logging queue is full, drop the line.
314  * This is to be used only in parts of code that would be dead-locked with the
315  * logger in case of a full disk.
316  *
317  * ie: anything on the path of the HUP signal handling.
318  *
319  * @param handle        handle to use, can be NULL
320  * @param level         level of the message
321  * @param fmt           format string
322  * @param ...           parameters for the format
323  */
324 
325 void logger_handle_try_msg(logger_handle* handle, u32 level, const char* fmt, ...);
326 
327 /**
328  * Try to send a formatted text to the logger.
329  * If the logging queue is full, drop the line.
330  * This is to be used only in parts of code that would be dead-locked with the
331  * logger in case of a full disk.
332  *
333  * ie: anything on the path of the HUP signal handling.
334  *
335  * @param handle        handle to use, can be NULL
336  * @param level         level of the message
337  * @param text          text to send
338  * @param text_len      length of the text to send
339  */
340 
341 void logger_handle_try_msg_text(logger_handle *handle, u32 level, const char* text, u32 text_len);
342 
343 
344 /**
345  * Sets the layout for the logged memory dumps
346  * Values MUST be set to (2^n)-1 with n >= 0
347  * Values MUST be < 256
348  *
349  * @param group_mask        The mask to group the bytes together (ie: 3 for making groups of 4)
350  * @param separator_mask    the mask to put a space separator every few bytes (ie: 3 for every 4 bytes)
351  *
352  */
353 
354 void log_memdump_set_layout(u32 group_mask, u32 separator_mask);
355 
356 /**
357  * Dumps memory in to the logger
358  *
359  * @param hndl          handle to use, can be NULL
360  * @param level         level of the message
361  * @param data_pointer  memory to dump
362  * @param size          size of the memory to dump
363  * @param line_size     length of a line
364  * @param flags         see osprint_dump for details: OSPRINT_DUMP_ADDRESS, OSPRINT_DUMP_HEX, OSPRINT_DUMP_TEXT
365  */
366 
367 void log_memdump_ex(logger_handle* hndl, u32 level, const void* data_pointer, ssize_t size, ssize_t line_size, u32 flags);
368 void log_memdump(logger_handle* hndl, u32 level, const void* data_pointer, ssize_t size, ssize_t line_size);
369 
370 void log_msghdr(logger_handle* hndl, u32 level, struct msghdr *hdr);
371 
372 void logger_handle_exit_level(u32 level);
373 
374 void logger_handle_finalize();
375 
376 void logger_set_level(u8 level);
377 
378 #if DNSCORE_HAS_LOG_THREAD_TAG
379 
380 void logger_handle_set_thread_tag_with_pid_and_tid(pid_t pid, thread_t tid, const char tag[THREAD_TAG_SIZE]);
381 void logger_handle_clear_thread_tag_with_pid_and_tid(pid_t pid, thread_t tid);
382 void logger_handle_set_thread_tag(const char tag[THREAD_TAG_SIZE]);
383 void logger_handle_clear_thread_tag();
384 
385 #else
386 
logger_handle_set_thread_tag_with_pid_and_tid(pid_t pid,thread_t tid,const char tag[1])387 static inline void logger_handle_set_thread_tag_with_pid_and_tid(pid_t pid, thread_t tid, const char tag[1])
388 {
389     (void)pid;
390     (void)tid;
391     (void)tag;
392 }
393 
logger_handle_clear_thread_tag_with_pid_and_tid(pid_t pid,thread_t tid)394 static inline void logger_handle_clear_thread_tag_with_pid_and_tid(pid_t pid, thread_t tid)
395 {
396     (void)pid;
397     (void)tid;
398 }
399 
logger_handle_set_thread_tag(const char tag[1])400 static inline void logger_handle_set_thread_tag(const char tag[1])
401 {
402     (void)tag;
403 }
404 
logger_handle_clear_thread_tag()405 static inline void logger_handle_clear_thread_tag()
406 {
407 }
408 
409 #endif
410 
411 
412 #define LOG_MEMDUMP_LAYOUT_DENSE 0xff,0xff
413 #define LOG_MEMDUMP_LAYOUT_ERIC 3,0xff
414 #define LOG_MEMDUMP_LAYOUT_GERY 0,3
415 
416 /*
417  * GCC style :
418  *
419  * #define debug(vararg...) logger_handle_msg(NULL,MSG_DEBUG,vararg)
420  *
421  * C99 style :
422  *
423  * #define debug(...) logger_handle_msg(NULL,MSG_DEBUG,__VA_ARGS__)
424  *
425  */
426 
427 #if defined(MODULE_MSG_HANDLE)
428     #define debug(...)  logger_handle_msg((MODULE_MSG_HANDLE),MSG_DEBUG,__VA_ARGS__)
429 #else
430     #define debug(...)  logger_handle_msg(NULL,MSG_DEBUG,__VA_ARGS__)
431 #endif
432 
433 /**
434  * LOG_TEXT_PREFIX is a text constant that will be prefixed to every text logged in the current source file.
435  * It is a constant that MUST be set before including logger_handle.h (or any logger header)
436  */
437 
438 #if !defined(LOG_TEXT_PREFIX)
439 #define LOG_TEXT_PREFIX
440 #endif
441 
442 #if LOGGER_EARLY_CULL
443 
444 // #define LOGGER_EARLY_CULL_PREFIX(__MSGLEVEL__) if(MODULE_MSG_HANDLE->channels[__MSGLEVEL__].offset >= 0)
445 // if(MODULE_MSG_HANDLE->channels[__MSGLEVEL__].offset >= 0)
446 // ptr +              k1 + level * k2 + k3
447 // if(table[MODULE_MSG_INDEX].channel[__MSGLEVEL__].offset >= 0
448 // ptr + index * k0 + k1 + level * k2 + k3
449 //
450 // proposed optimisation:
451 // ptr + level <- choosen one (obviously)
452 // ptr + index * k0 + level
453 // note: k0 = 64, k1 = 0, k2 = 16
454 // if index = index * k0, it's still one addition that could be removed
455 // if channel cannot be destroyed once created but only disabled, setting the ptr once is enough
456 // it still means children must be spawned after the channels are setup
457 // I don't see this as a problem as channel names are hard-coded in the binaries
458 //
459 
460 #define LOGGER_EARLY_CULL_PREFIX(__MSGLEVEL__) if(MODULE_MSG_HANDLE->active[__MSGLEVEL__] != 0)
461 
log_is_set(logger_handle * handle,int level)462 static inline bool log_is_set(logger_handle* handle, int level)
463 {
464     return (handle != NULL) && (handle->channels[level].offset >= 0);
465 }
466 
467 #define log_debug7(...) LOGGER_EARLY_CULL_PREFIX(MSG_DEBUG7) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_DEBUG7,LOG_TEXT_PREFIX __VA_ARGS__)
468 #define log_debug6(...) LOGGER_EARLY_CULL_PREFIX(MSG_DEBUG6) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_DEBUG6,LOG_TEXT_PREFIX __VA_ARGS__)
469 #define log_debug5(...) LOGGER_EARLY_CULL_PREFIX(MSG_DEBUG5) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_DEBUG5,LOG_TEXT_PREFIX __VA_ARGS__)
470 #define log_debug4(...) LOGGER_EARLY_CULL_PREFIX(MSG_DEBUG4) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_DEBUG4,LOG_TEXT_PREFIX __VA_ARGS__)
471 #define log_debug3(...) LOGGER_EARLY_CULL_PREFIX(MSG_DEBUG3) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_DEBUG3,LOG_TEXT_PREFIX __VA_ARGS__)
472 #define log_debug2(...) LOGGER_EARLY_CULL_PREFIX(MSG_DEBUG2) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_DEBUG2,LOG_TEXT_PREFIX __VA_ARGS__)
473 #define log_debug1(...) LOGGER_EARLY_CULL_PREFIX(MSG_DEBUG1) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_DEBUG1,LOG_TEXT_PREFIX __VA_ARGS__)
474 #define log_debug(...)  LOGGER_EARLY_CULL_PREFIX(MSG_DEBUG) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_DEBUG,LOG_TEXT_PREFIX __VA_ARGS__)
475 #define log_notice(...) LOGGER_EARLY_CULL_PREFIX(MSG_NOTICE) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_NOTICE,LOG_TEXT_PREFIX __VA_ARGS__)
476 #define log_info(...)   LOGGER_EARLY_CULL_PREFIX(MSG_INFO) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_INFO,LOG_TEXT_PREFIX __VA_ARGS__)
477 #define log_warn(...)   LOGGER_EARLY_CULL_PREFIX(MSG_WARNING) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_WARNING,LOG_TEXT_PREFIX __VA_ARGS__)
478 #define log_err(...)    LOGGER_EARLY_CULL_PREFIX(MSG_ERR) logger_handle_msg_nocull(MODULE_MSG_HANDLE,MSG_ERR,LOG_TEXT_PREFIX __VA_ARGS__)
479 #define log_to_level(level_,...)    LOGGER_EARLY_CULL_PREFIX((level_)) logger_handle_msg_nocull(MODULE_MSG_HANDLE,(level_),LOG_TEXT_PREFIX __VA_ARGS__)
480 
481 #define log_try_debug7(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG7,LOG_TEXT_PREFIX __VA_ARGS__)
482 #define log_try_debug6(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG6,LOG_TEXT_PREFIX __VA_ARGS__)
483 #define log_try_debug5(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG5,LOG_TEXT_PREFIX __VA_ARGS__)
484 #define log_try_debug4(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG4,LOG_TEXT_PREFIX __VA_ARGS__)
485 #define log_try_debug3(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG3,LOG_TEXT_PREFIX __VA_ARGS__)
486 #define log_try_debug2(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG2,LOG_TEXT_PREFIX __VA_ARGS__)
487 #define log_try_debug1(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG1,LOG_TEXT_PREFIX __VA_ARGS__)
488 #define log_try_debug(...)  logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG,LOG_TEXT_PREFIX __VA_ARGS__)
489 #define log_try_notice(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_NOTICE,LOG_TEXT_PREFIX __VA_ARGS__)
490 #define log_try_info(...)   logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_INFO,LOG_TEXT_PREFIX __VA_ARGS__)
491 #define log_try_warn(...)   logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_WARNING,LOG_TEXT_PREFIX __VA_ARGS__)
492 #define log_try_err(...)    logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_ERR,LOG_TEXT_PREFIX __VA_ARGS__)
493 /* Obsolete, Critical error: quit */
494 #define log_try_quit(...)   logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_CRIT,LOG_TEXT_PREFIX __VA_ARGS__)
495 /* Critical error: quit */
496 #define log_try_crit(...)   logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_CRIT,LOG_TEXT_PREFIX __VA_ARGS__)
497 /* Emergency: quit      */
498 #define log_try_emerg(...)  logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_EMERG,LOG_TEXT_PREFIX __VA_ARGS__)
499 #else
500 #define log_debug7(...) logger_handle_msg(MODULE_MSG_HANDLE,MSG_DEBUG7,LOG_TEXT_PREFIX __VA_ARGS__)
501 #define log_debug6(...) logger_handle_msg(MODULE_MSG_HANDLE,MSG_DEBUG6,LOG_TEXT_PREFIX __VA_ARGS__)
502 #define log_debug5(...) logger_handle_msg(MODULE_MSG_HANDLE,MSG_DEBUG5,LOG_TEXT_PREFIX __VA_ARGS__)
503 #define log_debug4(...) logger_handle_msg(MODULE_MSG_HANDLE,MSG_DEBUG4,LOG_TEXT_PREFIX __VA_ARGS__)
504 #define log_debug3(...) logger_handle_msg(MODULE_MSG_HANDLE,MSG_DEBUG3,LOG_TEXT_PREFIX __VA_ARGS__)
505 #define log_debug2(...) logger_handle_msg(MODULE_MSG_HANDLE,MSG_DEBUG2,LOG_TEXT_PREFIX __VA_ARGS__)
506 #define log_debug1(...) logger_handle_msg(MODULE_MSG_HANDLE,MSG_DEBUG1,LOG_TEXT_PREFIX __VA_ARGS__)
507 #define log_debug(...)  logger_handle_msg(MODULE_MSG_HANDLE,MSG_DEBUG,LOG_TEXT_PREFIX __VA_ARGS__)
508 #define log_notice(...) logger_handle_msg(MODULE_MSG_HANDLE,MSG_NOTICE,LOG_TEXT_PREFIX __VA_ARGS__)
509 #define log_info(...)   logger_handle_msg(MODULE_MSG_HANDLE,MSG_INFO,LOG_TEXT_PREFIX __VA_ARGS__)
510 #define log_warn(...)   logger_handle_msg(MODULE_MSG_HANDLE,MSG_WARNING,LOG_TEXT_PREFIX __VA_ARGS__)
511 #define log_err(...)    logger_handle_msg(MODULE_MSG_HANDLE,MSG_ERR,LOG_TEXT_PREFIX __VA_ARGS__)
512 
513 #define log_try_debug7(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG7,LOG_TEXT_PREFIX __VA_ARGS__)
514 #define log_try_debug6(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG6,LOG_TEXT_PREFIX __VA_ARGS__)
515 #define log_try_debug5(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG5,LOG_TEXT_PREFIX __VA_ARGS__)
516 #define log_try_debug4(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG4,LOG_TEXT_PREFIX __VA_ARGS__)
517 #define log_try_debug3(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG3,LOG_TEXT_PREFIX __VA_ARGS__)
518 #define log_try_debug2(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG2,LOG_TEXT_PREFIX __VA_ARGS__)
519 #define log_try_debug1(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG1,LOG_TEXT_PREFIX __VA_ARGS__)
520 #define log_try_debug(...)  logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_DEBUG,LOG_TEXT_PREFIX __VA_ARGS__)
521 #define log_try_notice(...) logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_NOTICE,LOG_TEXT_PREFIX __VA_ARGS__)
522 #define log_try_info(...)   logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_INFO,LOG_TEXT_PREFIX __VA_ARGS__)
523 #define log_try_warn(...)   logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_WARNING,LOG_TEXT_PREFIX __VA_ARGS__)
524 #define log_try_err(...)    logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_ERR,LOG_TEXT_PREFIX __VA_ARGS__)
525 #endif
526 
527 /* Obsolete, Critical error: quit */
528 #define log_quit(...)   logger_handle_msg(MODULE_MSG_HANDLE,MSG_CRIT,LOG_TEXT_PREFIX __VA_ARGS__)
529 /* Critical error: quit */
530 #define log_crit(...)   logger_handle_msg(MODULE_MSG_HANDLE,MSG_CRIT,LOG_TEXT_PREFIX __VA_ARGS__)
531 /* Emergency: quit      */
532 #define log_emerg(...)  logger_handle_msg(MODULE_MSG_HANDLE,MSG_EMERG,LOG_TEXT_PREFIX __VA_ARGS__)
533 
534 /* Obsolete, Critical error: quit */
535 #define log_try_quit(...)   logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_CRIT,LOG_TEXT_PREFIX __VA_ARGS__)
536 /* Critical error: quit */
537 #define log_try_crit(...)   logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_CRIT,LOG_TEXT_PREFIX __VA_ARGS__)
538 /* Emergency: quit      */
539 #define log_try_emerg(...)  logger_handle_try_msg(MODULE_MSG_HANDLE,MSG_EMERG,LOG_TEXT_PREFIX __VA_ARGS__)
540 
541 /* -7----------------------------------------------------------------------------
542  *
543  *      MACROS
544  */
545 
546 #if DEBUG
547 #define DERROR_MSG(...) logger_handle_msg(MODULE_MSG_HANDLE,MSG_ERR,__VA_ARGS__)
548 #else
549 #define DERROR_MSG(...)   /* nothing */
550 #endif /* DEBUG */
551 
552 /**
553  * For practical reasons, the code for logger_init() is in logger_handle.c
554  */
555 
556 void logger_init();
557 
558 void logger_init_ex(u32 queue_size, size_t shared_heap_size);
559 
560 /**
561  * For practical reasons, the code for logger_start() is in logger_handle.c
562  */
563 
564 void logger_start();
565 void logger_start_server();
566 void logger_stop_server();
567 void logger_start_client();
568 void logger_stop_client();
569 
570 u8 logger_set_shared_heap(u8 id);
571 
572 /**
573  * For practical reasons, the code for logger_stop() is in logger_handle.c
574  */
575 
576 void logger_stop();
577 
578 /**
579  * For practical reasons, the code for logger_finalize() is in logger_handle.c
580  */
581 
582 void logger_finalize();
583 
584 /**
585  * For practical reasons, the code for logger_flush() is in logger_handle.c
586  */
587 
588 void logger_flush();
589 
590 /**
591  * The next message seen by the logger will trigger a sink.
592  */
593 
594 void logger_sink_noblock();
595 
596 /**
597  * Asks all channels to verify their output is valid and if not, to discard
598  * all content to a sink until reopen is called.
599  */
600 
601 void logger_sink();
602 
603 /**
604  * For practical reasons, the code for logger_reopen() is in logger_handle.c
605  */
606 
607 void logger_reopen();
608 
609 bool logger_is_running();
610 
611 /**
612  * Sets the logger queue size
613  */
614 
615 u32  logger_set_queue_size(u32 n);
616 
617 void logger_set_path(const char *path);
618 const char* logger_get_path();
619 
620 void  logger_release_ownership();
621 void  logger_take_ownership(pid_t new_owner);
622 
623 void logger_set_uid(uid_t uid);
624 uid_t logger_get_uid();
625 
626 void logger_set_gid(uid_t gid);
627 gid_t logger_get_gid();
628 
629 /**
630  * Polls for the state of the logger.
631  * Made for a specific task.
632  * Use with care, or not at all.
633  */
634 
635 bool logger_wait_started();
636 
637 #ifdef	__cplusplus
638 }
639 #endif
640 
641 #endif	/* _LOGGER_HANDLE_H */
642 /** @} */
643