Mstdlib-1.24.0
m_log.h
1/* The MIT License (MIT)
2 *
3 * Copyright (c) 2017 Monetra Technologies, LLC.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24#ifndef M_LOG_H
25#define M_LOG_H
26
27#include <mstdlib/mstdlib_io.h>
28
29__BEGIN_DECLS
30
31
32
33/*! \addtogroup m_log_tag_ranges Tag Ranges
34 * \ingroup m_log
35 *
36 * Helpers for constructing ranges of power-of-two tags.
37 *
38 * @{
39 */
40
41/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42 * Helpers for constructing ranges of power-of-two tags */
43
44/*! Convenience constant - when passed to a function that accepts multiple tags, indicates ALL tags should be used.
45 *
46 * \see M_log_all_tags_lt
47 * \see M_log_all_tags_lte
48 * \see M_log_all_tags_gt
49 * \see M_log_all_tags_gte
50 */
51#define M_LOG_ALL_TAGS M_UINT64_MAX
52
53
54/*! Return all tags less than the given power-of-two tag, OR'd together.
55 *
56 * \see M_LOG_ALL_TAGS
57 * \see M_log_all_tags_lte
58 * \see M_log_all_tags_gt
59 * \see M_log_all_tags_gte
60 *
61 * \param[in] tag single power-of-two tag value
62 * \return all tags < given tag
63 */
64M_uint64 M_log_all_tags_lt(M_uint64 tag);
65
66
67/*! Return all tags less than or equal to the given power-of-two tag, OR'd together.
68 *
69 * \see M_LOG_ALL_TAGS
70 * \see M_log_all_tags_lt
71 * \see M_log_all_tags_gt
72 * \see M_log_all_tags_gte
73 *
74 * \param[in] tag single power-of-two tag value
75 * \return all tags <= given tag
76 */
77M_uint64 M_log_all_tags_lte(M_uint64 tag);
78
79
80/*! Return all tags greater than the given power-of-two tag, OR'd together.
81 *
82 * \see M_LOG_ALL_TAGS
83 * \see M_log_all_tags_lt
84 * \see M_log_all_tags_lte
85 * \see M_log_all_tags_gte
86 *
87 * \param[in] tag single power of two tag value
88 * \return all tags > given tag
89 */
90M_uint64 M_log_all_tags_gt(M_uint64 tag);
91
92
93/*! Return all tags greater than or equal to the given power-of-two tag, OR'd together.
94 *
95 * \see M_LOG_ALL_TAGS
96 * \see M_log_all_tags_lt
97 * \see M_log_all_tags_lte
98 * \see M_log_all_tags_gt
99 *
100 * \param[in] tag single power of two tag value
101 * \return all tags >= given tag
102 */
103M_uint64 M_log_all_tags_gte(M_uint64 tag);
104
105/*! @} */ /* End of Tag Ranges group */
106
107
108
109
110/*! \addtogroup m_log_common Common
111 * \ingroup m_log
112 *
113 * Common logging functions.
114 *
115 * @{
116 */
117
118/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
119/* ---- Types ---- */
120
121/*! Opaque struct that maintains state for the logging system. */
122typedef struct M_log M_log_t;
123
124
125/*! Opaque handle used to refer to individual log modules. DON'T FREE THIS. */
126typedef struct M_log_module M_log_module_t;
127
128
129/*! Function type for per-module prefix callbacks.
130 *
131 * This will be called every time a log message is sent to the module. It allows you to add a custom prefix
132 * after the timestamp string, by letting you append to the message buffer before the log message is added:
133 *
134 * \verbatim 03-02-2012 08:05:32<your prefix here>... log message ...<line end char> \endverbatim
135 *
136 * Note that no spaces or separator chars are automatically added between the timestamp string, your prefix,
137 * and the log message.
138 *
139 * If no prefix callback is provided, the default prefix \c ": " will be added instead.
140 *
141 * \warning
142 * Do not call any M_log_* or M_log_module_* functions from inside a prefix callback, it will cause a deadlock.
143 *
144 * \warning
145 * Do not write line-end characters in a prefix. Some logging modules don't handle multiple-line messages very well,
146 * and line-end chars are not automatically removed from custom prefixes.
147 *
148 * \warning
149 * May be called simultaneously from multiple threads. If the content of prefix_thunk may be modified after
150 * it's passed to a module, you should include your own locks inside the thunk and use them inside the callback.
151 *
152 * \see M_log_set_prefix()
153 *
154 * \param[in] prefix_thunk thunk passed to M_log_set_prefix()
155 * \param[in] msg_thunk thunk passed to M_printf() or M_vprintf()
156 * \param[in] msg_buf message buffer (append prefix to this)
157 * \param[in] tag tag of message we're prefixing
158 */
159typedef void (*M_log_prefix_cb)(M_buf_t *msg_buf, M_uint64 tag, void *prefix_thunk, void *msg_thunk);
160
161
162/*! Function type for per-module filtering callbacks.
163 *
164 * This will be called every time a log message is sent to the module. If the function returns M_FALSE,
165 * the message will be ignored by the module.
166 *
167 * \warning
168 * Do not call any M_log_* or M_log_module_* functions from inside a filter callback, it will cause a deadlock.
169 *
170 * \warning
171 * May be called simultaneously from multiple threads. If the content of filter_thunk may be modified after
172 * it's passed to a module, you should include your own locks inside the thunk and use them inside the callback.
173 *
174 * \see M_log_module_set_filter()
175 *
176 * \param[in] filter_thunk thunk passed to M_log_module_set_filter()
177 * \param[in] msg_thunk thunk passed to M_log_printf() or M_log_vprintf()
178 * \param[in] tag tag of message we're filtering
179 * \return M_TRUE if this module will accept the given tag, M_FALSE otherwise
180 */
181typedef M_bool (*M_log_filter_cb)(M_uint64 tag, void *filter_thunk, void *msg_thunk);
182
183
184/*! Function type for callback that's called when a module expires.
185 *
186 * This will be called by the log whenever a module expires and is automatically removed. Currently, only the
187 * membuf module has an automatic expiration date. The callback is not called when a module is removed by normal,
188 * user-initiated means like M_log_module_remove() or M_log_module_take_membuf().
189 *
190 * Note that the callback is called AFTER the module is removed from the log. So, at the time the callback
191 * is called, the module handle is already invalid.
192 *
193 * \warning
194 * This callback may be called simultaneously by multiple internal threads. If the callback modifies some shared
195 * datastructure, you MUST use your own locks to prevent concurrent access to that datastructure.
196 *
197 * \see M_log_module_add_membuf()
198 *
199 * \param[in] module handle of membuf module that was just removed (invalid)
200 * \param[in] thunk thunk passed to M_log_module_add_membuf()
201 */
202typedef void (*M_log_expire_cb)(M_log_module_t *module, void *thunk);
203
204
205/*! Function type for destructors. */
206typedef void (*M_log_destroy_cb)(void *thunk);
207
208
209/*! Error codes for the logging system. */
210typedef enum {
211 M_LOG_SUCCESS = 0, /*!< Operation succeeded. */
212
213 M_LOG_INVALID_PARAMS, /*!< Given parameters invalid (usually a NULL pointer) */
214 M_LOG_INVALID_PATH, /*!< Given filesystem path couldn't be normalized */
215 M_LOG_INVALID_TAG, /*!< Single tags must be non-zero and a power of two */
216 M_LOG_NO_EVENT_LOOP, /*!< No event loop specified for log, can't use event-based modules. */
217 M_LOG_SUSPENDED, /*!< Log has been suspended, can't take the requested action until resume is called */
218 M_LOG_DUPLICATE_TAG_NAME, /*!< Given name has already been assigned to a different tag */
219 M_LOG_UNREACHABLE, /*!< Requested resource unreachable (can't connect to host, can't open file on disk) */
220 M_LOG_INVALID_TIME_FORMAT, /*!< Given time format string is invalid (can't be parsed) */
221 M_LOG_MODULE_UNSUPPORTED, /*!< The given module type is not supported on this OS */
222 M_LOG_MODULE_NOT_FOUND, /*!< The requested module has already been removed from the logger */
223 M_LOG_WRONG_MODULE, /*!< Module-specific function was run on the wrong module */
224 M_LOG_GENERIC_FAIL /*!< Generic internal module failure occurred (usually an IO error) */
226
227
228/*! Logging module types. */
229typedef enum {
230 M_LOG_MODULE_NULL = 0, /*!< Type that represents invalid or unset module type*/
231 M_LOG_MODULE_STREAM, /*!< Module that outputs to stdout or stderr */
232 M_LOG_MODULE_NSLOG, /*!< Module that outputs to macOS/iOS logging system (NSLog) */
233 M_LOG_MODULE_ANDROID, /*!< Module that outputs to android logging system */
234 M_LOG_MODULE_FILE, /*!< Module that outputs to a set of files on the filesystem */
235 M_LOG_MODULE_SYSLOG, /*!< Module that outputs directly to a local syslog daemon */
236 M_LOG_MODULE_TSYSLOG, /*!< Module that outputs to a remove syslog daemon using TCP */
237 M_LOG_MODULE_MEMBUF /*!< Module that outputs to a temporary memory buffer */
239
240
241/*! Control what type of line endings get automatically appended to log messages. */
242typedef enum {
243 M_LOG_LINE_END_NATIVE, /*!< \c '\\n' if running on Unix, \c '\\r\\n' if running on Windows */
244 M_LOG_LINE_END_UNIX, /*!< always use \c '\\n' */
245 M_LOG_LINE_END_WINDOWS /*!< always use \c '\\r\\n' */
247
248
249/*! Types of output streams that can be used for the stream module. */
250typedef enum {
251 M_STREAM_STDOUT, /*!< Output log messages to \c stdout */
252 M_STREAM_STDERR /*!< Output log messages to \c stderr */
254
255
256/*! Standard facility types for syslog and tcp_syslog modules. */
257typedef enum {
269
270
271/*! Standard log priority types for syslog and tcp_syslog modules.
272 *
273 * Listed in enum in order of descending priority (highest priority --> lowest priority).
274 *
275 * It is up to the caller to define the mapping between their own logging tags and the syslog
276 * priority levels. These mappings are defined on a per-module basis.
277 *
278 * \see M_log_module_syslog_set_tag_priority
279 * \see M_log_module_tcp_syslog_set_tag_priority
280 */
281typedef enum {
290} M_syslog_priority_t; /* Note: enum values can't exceed 78, since we append them to msg as a writable char */
291
292
293/*! Standard log priority types for android log module.
294 *
295 * Listed in enum in order of descending priority (highest priority --> lowest priority).
296 *
297 * \see M_log_module_android_set_tag_priority
298 */
299typedef enum {
306} M_android_log_priority_t; /* Note: enum values can't exceed 78, since we append them to msg as a writable char */
307
308
309
310/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
311/* ---- General log functions. ---- */
312
313/*! Return human-readable string describing the given error code.
314 *
315 * \param[in] err error code
316 * \return human-readable descriptive string
317 */
318M_API const char *M_log_err_to_str(M_log_error_t err);
319
320
321/*! Create a new log manager.
322 *
323 * When first created, the log manager will accept messages, but won't output anything. The desired
324 * output modules must be added and configured after the logger is created. You can add any number
325 * or combination of the output modules.
326 *
327 * To free the logger object, you must call M_log_destroy() or M_log_destroy_blocking().
328 *
329 * If \a flush_on_destroy is set to M_TRUE, log modules won't be destroyed until all messages in their queue (if any)
330 * are written. Otherwise, log modules will be destroyed immediately after the message currently being written is done.
331 *
332 * If you don't plan on adding any event-based modules (like tcp_syslog), you can pass \c NULL for
333 * the event pointer.
334 *
335 * \see M_log_module_add_stream
336 * \see M_log_module_add_file
337 * \see M_log_module_add_syslog
338 * \see M_log_module_add_tcp_syslog
339 * \see M_log_module_add_membuf
340 * \see M_log_destroy
341 * \see M_log_destroy_blocking
342 *
343 * \param[in] mode line-ending mode
344 * \param[in] flush_on_destroy if M_TRUE, wait until message queue is empty when destroying a module
345 * \param[in] event external event loop to use for event-based modules (not owned by logger)
346 *
347 * \return new logger object
348 */
349M_API M_log_t *M_log_create(M_log_line_end_mode_t mode, M_bool flush_on_destroy, M_event_t *event);
350
351
352/*! Destroy the logger (non-blocking).
353 *
354 * Sends a message to each module requesting that it stop at the next opportunity and destroy itself,
355 * then immediately destroys the logger.
356 *
357 * Worker threads will try to clean themselves up gracefully, after this function returns (if the process
358 * doesn't end before they have a chance to).
359 *
360 * \see M_log_destroy_blocking
361 *
362 * \param[in] log logger object
363 */
364M_API void M_log_destroy(M_log_t *log);
365
366
367/*! Destroy the logger (blocking).
368 *
369 * Sends a message to each module requesting that it stop at the next opportunity. Once all internal
370 * worker threads have stopped, destroys all the modules and the logger.
371 *
372 * If the timeout is reached before all modules have stopped, non-blocking destroys will be triggered for
373 * the remaining modules.
374 *
375 * In order to avoid blocking the event loop, backend modules like TCP syslog which are event-based (no
376 * worker threads) will not block when this function is called. Instead, they will execute a normal
377 * non-blocking destroy. To give these backends time to exit cleanly, make sure to call
378 * M_event_done_with_disconnect() after this function, and pass non-zero values to both timeouts.
379 *
380 * Example:
381 * \code
382 * M_event_t event_loop = ...;
383 * M_log_t *log = M_log_create(..., event_loop, ...);
384 * ...
385 * // Block up to five seconds while threaded backends try to exit cleanly.
386 * M_log_destroy_blocking(log, 5000);
387 *
388 * // Wait up to five seconds for top-level handlers added by event-based log backends to close their
389 * // own I/O objects. Then, wait up to 1 second to force clean disconnects on any I/O objects
390 * // that are still open.
391 * M_event_done_with_disconnect(event_loop, 5000, 1000);
392 *
393 * M_event_destroy(event_loop);
394 * \endcode
395 *
396 * \see M_log_destroy
397 *
398 * \param[in] log logger object
399 * \param[in] timeout_ms amount of time to wait for modules to finish before giving up, or 0 to never give up
400 */
401M_API void M_log_destroy_blocking(M_log_t *log, M_uint64 timeout_ms);
402
403
404/*! Set timestamp format for all future log messages.
405 *
406 * If not set, the default timestamp format \c "%Y-%M-%DT%H:%m:%s.%l%Z" (ISO8601) will be used.
407 *
408 * If the given time format string is empty or invalid, an error will be returned
409 * and the old time format string will be preserved.
410 *
411 * Specifiers accepted in time format string:
412 * - %%t -- Unix timestamp
413 * - %%M -- 2 digit month
414 * - %%a -- abbreviated month (Jan/Feb/Mar, etc)
415 * - %%D -- 2 digit day of month
416 * - %%d -- abbreviated day of week (Sun/Mon/Tue, etc)
417 * - %%Y -- 4 digit year
418 * - %%y -- 2 digit year
419 * - %%H -- 2 digit hour
420 * - %%m -- 2 digit minute
421 * - %%s -- 2 digit second
422 * - %%l -- 3 digit millisecond
423 * - %%u -- 6 digit microsecond
424 * - %%z -- timezone offset (without colon)
425 * - %%Z -- timezone offset (with colon)
426 *
427 * For example "[%D/%a/%Y:%H:%m:%s.%l %z]" might give a prefix like:
428 * [11/Jan/2008:09:19:11.654 -0500]
429 *
430 * \param[in] log logger object
431 * \param[in] fmt time format string
432 * \return error code
433 */
434M_API M_log_error_t M_log_set_time_format(M_log_t *log, const char *fmt);
435
436
437/*! Associate a name with the given tag.
438 *
439 * If a name is specified for the given tag, it will be added to the message prefix, in between the
440 * timestamp and the custom prefix.
441 *
442 * Alternatively, since the tag gets passed into the custom prefix callback, you can add the tag name
443 * there instead of using this.
444 *
445 * Tag names must be unique (case-insensitive). If you try to assign the same name to two tags, you'll
446 * get an error code on the second (M_LOG_DUPLICATE_NAME).
447 *
448 * \param log logger object
449 * \param tag user-defined tag (must be a single power-of-two tag)
450 * \param name name to associate with this tag (NULL or empty string to remove an existing name association)
451 * \return error code
452 */
453M_API M_log_error_t M_log_set_tag_name(M_log_t *log, M_uint64 tag, const char *name);
454
455
456/*! Get the name associated with the given tag.
457 *
458 * \warning
459 * DO NOT call this method from a prefix or filter callback, it will cause a deadlock.
460 *
461 * \param log logger object
462 * \param tag user-defined tag (must be a single power-of-two tag)
463 * \return name of tag, or NULL if there's no name stored or some other error occurred
464 */
465M_API const char *M_log_get_tag_name(M_log_t *log, M_uint64 tag);
466
467
468/*! Get the tag associated with the given name (case-insensitive).
469 *
470 * \warning
471 * DO NOT call this method from a prefix or filter callback, it will cause a deadlock.
472 *
473 * \param log logger object
474 * \param name name that has been previously associated with a tag (case doesn't matter)
475 * \return tag associated with the given name, or 0 if there's no tag with this name or some other error occurred
476 */
477M_API M_uint64 M_log_get_tag(M_log_t *log, const char *name);
478
479
480/*! Control whether the log should pad names out to a common width or not.
481 *
482 * By default, tag names are unpadded. However, if you use this function to enable padding,
483 * all tag names will be padded with spaces on the right out to the width of the longest
484 * name added to the log so far.
485 *
486 * \param log logger object
487 * \param padded M_TRUE if tag names should be padded on output, M_FALSE if not (the default)
488 * \return error code
489 */
491
492
493/*! Write a formatted message to the log.
494 *
495 * Multi-line messages will be split into a separate log message for each line.
496 *
497 * A timestamp prefix will be automatically added to the start of each line, formatted according to the string set in
498 * M_log_set_time_format(). All the lines from a single call to M_printf() will be given identical timestamps.
499 *
500 * The message will then be sent to each individual logging module for further processing, if the given message tag is
501 * in the list of accepted tags for the module (as set by M_log_module_set_accepted_tags()). A given module may also
502 * be skipped if a filter callback was set for the module and it rejected the message.
503 *
504 * For each module that accepts the message, a prefix callback is called (if set) that appends additional text to each
505 * line's prefix, immediately following the timestamp string. The formatted message itself is then added, followed by
506 * the line-end characters corresponding to the current line-ending mode. The finished message is then sent on to the
507 * module.
508 *
509 * Note that the per-message thunk only needs to be valid until M_log_printf() returns - you can put non-const data
510 * in here. This thunk is caller-managed - it's not freed or otherwise kept track of internally.
511 *
512 * \param[in] log logger object
513 * \param[in] tag user-defined tag attached to this message (must be a single power-of-two tag)
514 * \param[in] msg_thunk per-message thunk to pass to filter and prefix callbacks (only needs to be valid until function returns)
515 * \param[in] fmt format string, accepts same tags as M_printf()
516 * \return error code
517 */
518M_API M_log_error_t M_log_printf(M_log_t *log, M_uint64 tag, void *msg_thunk, const char *fmt, ...) M_PRINTF(4,5) M_WARN_NONNULL(4);
519
520
521/*! Write a formatted message to the log (var arg).
522 *
523 * Same as M_log_printf(), but accepts a variable argument list explicitly as a va_list. This is inteded to allow
524 * the user to define their own wrapper functions that take variable argument lists (...) and call M_log_vprintf()
525 * internally.
526 *
527 * \param[in] log logger object
528 * \param[in] tag user-defined tag attached to this message (must be a single power-of-two tag)
529 * \param[in] msg_thunk per-message thunk to pass to filter and prefix callbacks (only needs to be valid until function returns)
530 * \param[in] fmt format string, accepts same tags as M_printf()
531 * \param[in] ap list of arguments passed in from the calling vararg function
532 * \return error code
533 */
534M_API M_log_error_t M_log_vprintf(M_log_t *log, M_uint64 tag, void *msg_thunk, const char *fmt, va_list ap);
535
536
537/*! Write a message directly to the log.
538 *
539 * Same as M_log_printf(), but it takes a message directly, instead of a format string and a list of arguments.
540 *
541 * \param[in] log logger object
542 * \param[in] tag user-defined tag attached to this message (must be a single power-of-two tag)
543 * \param[in] msg_thunk per-message thunk to pass to filter and prefix callbacks (only needs to be valid until function returns)
544 * \param[in] msg message string
545 */
546M_API M_log_error_t M_log_write(M_log_t *log, M_uint64 tag, void *msg_thunk, const char *msg);
547
548
549/*! Perform an emergency message write, to all modules that allow such writes.
550 *
551 * \warning
552 * This function is EXTREMELY dangerous. It's meant to be called in a signal handler as the program is crashing,
553 * so it doesn't acquire any mutex locks, and it tries not to malloc anything. DON'T USE THIS FUNCTION IN NORMAL
554 * USAGE, IT IS NOT SAFE.
555 *
556 * \param[in] log logger object
557 * \param[in] msg emergency message to output
558 */
559M_API void M_log_emergency(M_log_t *log, const char *msg);
560
561
562/*! Reopen/refresh connections for all modules in the logger.
563 *
564 * This closes then re-opens existing file streams, syslog, TCP connections, etc. for every
565 * loaded module.
566 *
567 * Modules that don't open or close anything (membuf, stream, Android log, etc.) are unaffected by this command.
568 *
569 * \see M_log_module_reopen (if you only want to reopen a specific module)
570 *
571 * \param[in] log logger object
572 */
573M_API void M_log_reopen_all(M_log_t *log);
574
575
576/*! Suspend connections for all modules in the logger (BLOCKING).
577 *
578 * This closes existing file streams, syslog, TCP connections, etc. for every loaded module.
579 *
580 * For modules that have resources closed, messages will accumulate without any being written while suspended.
581 *
582 * Modules that don't open or close anything (membuf, stream, Android log, etc.) are unaffected by this command.
583 *
584 * \warning
585 * This call will block until every module that can be suspended reports that it is finished suspending itself.
586 * At worst, this means that we'll be blocked until whatever message is in the process of being written is done.
587 *
588 * \warning
589 * If you have modules that depend on an external event loop (like tcp_syslog), you must wait for the event
590 * loop to finish after calling suspend, and then destroy it. You then create a new event loop once you're
591 * ready to resume, and pass it into M_log_resume().
592 *
593 * \see M_log_resume
594 *
595 * \param[in] log logger object
596 */
597M_API void M_log_suspend(M_log_t *log);
598
599
600/*! Resume connections for all modules in the logger.
601 *
602 * This opens file streams, syslog, TCP connections, etc. that were closed by M_log_suspend().
603 *
604 * Modules that were previously suspended will now start pulling messages of the queue and writing them again.
605 *
606 * If you have any modules that use an external event loop, you must pass the new loop to use into this
607 * function (since you should have destroyed the old one after calling suspend). If you're not using
608 * event-based modules, you can just set this to NULL.
609 *
610 * \see M_log_suspend
611 *
612 * \param[in] log logger object
613 * \param[in] event external event loop to use for event-based modules (not owned by logger)
614 */
615M_API void M_log_resume(M_log_t *log, M_event_t *event);
616
617
618/*! Return list of handles of all currently loaded modules.
619 *
620 * The returned list is a snapshot of what modules were loaded when the function was called. Other threads may
621 * modify the internal list of modules after you get a copy, so the list of modules may not be accurate.
622 *
623 * The caller is responsible for freeing the returned list with M_list_destroy().
624 *
625 * \param[in] log logger object
626 * \return list of M_log_module_t pointers (module handles)
627 */
629
630
631
632/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
633/* Common module functions (see m_log_common.c). */
634
635/*! Check to see if the given module handle is still loaded in the logger.
636 *
637 * \see M_log_module_remove
638 *
639 * \param[in] log logger object
640 * \param[in] module handle of module to operate on
641 * \return M_TRUE if module hasn't been removed from the log yet, M_FALSE otherwise
642 */
643M_API M_bool M_log_module_present(M_log_t *log, M_log_module_t *module);
644
645
646/*! Return the type of the given module (file, stream, etc.).
647 *
648 * \param[in] log logger object
649 * \param[in] module handle of module to operate on
650 * \return type of module, or M_LOG_MODULE_NULL if module has already been removed
651 */
653
654
655/*! Associate the given user-defined tag(s) with the given module handle.
656 *
657 * If you don't associate any tags with a module, nothing will get written to it.
658 *
659 * \see M_LOG_ALL_TAGS
660 * \see M_log_all_tags_lt
661 * \see M_log_all_tags_lte
662 * \see M_log_all_tags_gt
663 * \see M_log_all_tags_gte
664 *
665 * \see M_log_module_get_accepted_tags
666 *
667 * \param[in] log logger object
668 * \param[in] module handle of module to operate on
669 * \param[in] tags user-defined power-of-two tag (or multiple power-of-two tags, OR'd together)
670 * \return error code
671 */
673
674
675/*! Return a snapshot of the user-defined tag(s) currently associated with the given module handle.
676 *
677 * \see M_log_module_set_accepted_tags
678 *
679 * \param[in] log logger object
680 * \param[in] module handle of module to operate on
681 * \param[out] out_tags tag snapshot will be placed here, or 0 if no tags are associated with this module
682 * \return error code
683 */
685
686
687/*! Associate a prefix callback with the given module handle.
688 *
689 * This exists only for legacy compatibility. Do Not use. It does not associate with a module.
690 *
691 * \see M_log_set_prefix
692 *
693 *
694 * \param[in] log logger object
695 * \param[in] module handle of module to operate on
696 * \param[in] prefix_cb prefix callback (function pointer)
697 * \param[in] prefix_thunk any state used by prefix callback
698 * \param[in] thunk_destroy_cb function to call when destroying the prefix thunk
699 * \return error code
700 */
702 void *prefix_thunk, M_log_destroy_cb thunk_destroy_cb);
703
704
705/* Associate a prefix callback with the log system.
706 *
707 * The prefix callback allows the user to add a string between the timestamp and the body of the log message.
708 * If no prefix callback is provided, the default prefix of ": " will be used. See \link M_log_prefix_cb \endlink
709 * for more details.
710 *
711 * \see M_log_prefix_cb
712 * \see M_log_set_time_format
713 *
714 * \param[in] log logger object
715 * \param[in] prefix_cb prefix callback (function pointer)
716 * \param[in] prefix_thunk any state used by prefix callback
717 * \param[in] thunk_destroy_cb function to call when destroying the prefix thunk
718 * \return error code
719 */
721 void *prefix_thunk, M_log_destroy_cb thunk_destroy_cb);
722
723/*! Associate a filter callback with the given module handle.
724 *
725 * The filter callback allows the user to reject additional log messages. It is applied after the messages are
726 * filtered according to the list of accepted tags set by M_log_module_set_accepted_tags(). If no filter callback
727 * is provided, no additional filtering beyond the list of accepted tags will be performed. See
728 * \link M_log_filter_cb \endlink for more details.
729 *
730 * \see M_log_filter_cb
731 * \see M_log_module_set_accepted_tags
732 *
733 * \param[in] log logger object
734 * \param[in] module handle of module to operate on
735 * \param[in] filter_cb filter callback (function pointer)
736 * \param[in] filter_thunk any state used by filter callback
737 * \param[in] thunk_destroy_cb function to call when destroying the filter thunk
738 * \return error code
739 */
741 void *filter_thunk, M_log_destroy_cb thunk_destroy_cb);
742
743
744/*! Trigger a disconnect/reconnect of the given module's internal resource.
745 *
746 * The exact action taken by this command depends on the module. For example, the file module will close and reopen
747 * the internal connection to the main log file. Modules without closeable resources (like membuf and stream) treat
748 * this as a no-op.
749 *
750 * \see M_log_reopen_all (if you want to reopen all modules in the logger)
751 *
752 * \param[in] log logger object
753 * \param[in] module handle of module to operate on
754 * \return error code
755 */
757
758
759/*! Remove a module from the running log and destroy it.
760 *
761 * This function does not block. If the module is busy writing a message, it is removed from the list of active
762 * modules, and then it destroys itself asynchronously when the module is finished with its current chunk of work.
763 *
764 * \param[in] log logger object
765 * \param[in] module handle of module to destroy
766 * \return error code
767 */
769
770/*! @} */ /* End of Common group */
771
772
773
774
775/*! \addtogroup m_log_stream Stream Module
776 * \ingroup m_log
777 *
778 * Functions to enable logging to streams (stdout, stderr).
779 *
780 * Not available when building for Android platform.
781 *
782 * @{
783 */
784
785/*! Add a module to output to a standard stream (stdout, stderr).
786 *
787 * If the library was compiled on a platform that doesn't allow console output (e.g., Android), this function
788 * will return \link M_LOG_MODULE_UNSUPPORTED \endlink when called, and no module will be added to the logger.
789 *
790 * \warning
791 * Normally, you should only add at most one stream output module to a given M_log_t object. This is because
792 * having multiple backends write to the same console stream may cause the output from each thread to become
793 * intermingled and unreadable. Plus, there's only one global thing you're writing too, it doesn't make any
794 * sense to output to it from a bunch of separate worker threads. Just use one backend per destination.
795 *
796 * \param[in] log logger object
797 * \param[in] type what stream to output to (stdout, stderr)
798 * \param[in] max_queue_bytes max size of queue used to buffer asynchronous writes to the stream
799 * \param[in] out_mod handle for created module, or \c NULL if there was an error
800 * \return error code
801 */
802M_API M_log_error_t M_log_module_add_stream(M_log_t *log, M_stream_type_t type, size_t max_queue_bytes,
803 M_log_module_t **out_mod);
804
805/*! @} */ /* End of Stream group */
806
807
808
809
810/*! \addtogroup m_log_nslog NSLog Module
811 * \ingroup m_log
812 *
813 * Functions to enable logging to macOS/iOS logging subsytem (NSLog).
814 *
815 * Only available when building for Apple platforms.
816 *
817 * @{
818 */
819
820/*! Add a module to output to macOS/iOS logging subsystem (if we're building for an Apple platform).
821 *
822 * If the library wasn't compiled for an Apple device, this function will return \link M_LOG_MODULE_UNSUPPORTED \endlink
823 * when called, and no module will be added to the logger.
824 *
825 * \param[in] log logger object
826 * \param[in] max_queue_bytes max size of queue used to buffer asynchronous writer to NSLog
827 * \param[in] out_mod handle for created module, or \c NULL if there was an error
828 * \return error code
829 */
830M_API M_log_error_t M_log_module_add_nslog(M_log_t *log, size_t max_queue_bytes, M_log_module_t **out_mod);
831
832/*! @} */ /* End of NSLog group */
833
834
835
836
837/*! \addtogroup m_log_android Android Module
838 * \ingroup m_log
839 *
840 * Functions to enable logging to Android logging subsystem (__android_log_write).
841 *
842 * Only available when building for the Android platform.
843 *
844 * @{
845 */
846
847/*! Add a module to output to Android logging subsystem (if we're building for Android).
848 *
849 * Note: Android logging messages may be truncated by the subsystem to an implementation-specific
850 * line length limit (usually 1023 chars).
851 *
852 * Android logging allows passing a \c NULL or empty string for the product name - in this case, the "global"
853 * product name is used, not the name of the program like in syslog.
854 *
855 * If the library wasn't compiled for Android, this function will return \link M_LOG_MODULE_UNSUPPORTED \endlink
856 * when called, and no module will be added to the logger.
857 *
858 * \param[in] log logger object
859 * \param[in] product short tag string: name of program, or \c NULL to use "global" tag
860 * \param[in] max_queue_bytes max size of queue used to buffer asynchronous writes to android log
861 * \param[out] out_mod handle for created module, or \c NULL if there was an error
862 * \return error code
863 */
864M_API M_log_error_t M_log_module_add_android(M_log_t *log, const char *product, size_t max_queue_bytes,
865 M_log_module_t **out_mod);
866
867
868/*! Associate the given user-defined tag(s) with an Android log priority.
869 *
870 * If you don't associate a tag with an Android log priority, the default priority of \link M_ANDROID_LOG_INFO \endlink
871 * will be used for that tag.
872 *
873 * \see M_LOG_ALL_TAGS
874 * \see M_log_all_tags_lt
875 * \see M_log_all_tags_lte
876 * \see M_log_all_tags_gt
877 * \see M_log_all_tags_gte
878 *
879 * \param[in] log logger object
880 * \param[in] module handle of module to operate on
881 * \param[in] tags user-defined power-of-two tag (or multiple power-of-two tags, OR'd together)
882 * \param[in] priority single priority value to associate with the given tags
883 * \return error code
884 */
886 M_android_log_priority_t priority);
887
888/*! @} */ /* End of Android group */
889
890
891
892
893/*! \addtogroup m_log_file Filesystem Module
894 * \ingroup m_log
895 *
896 * Functions to enable logging to a group of files on disk. Includes support for log rotation and compression.
897 *
898 * @{
899 */
900
901/*! Add a module to output to a rotating list of files on disk.
902 *
903 * When archiving a file, the uncompressed file name will be appended directly onto whatever archive command is
904 * supplied by the user, then executed in its own process. In order for rotation to work correctly, the output
905 * file produced by the command must be exactly equal to <tt>[uncompressed file][archive_file_ext]</tt>.
906 *
907 * The automatic file rotation parameters (\a autorotate_size and \a autorotate_time_s) can be disabled by setting
908 * them to a value of 0. If both are disabled, rotations will only happen when M_log_module_file_rotate() is explicitly
909 * called by the user.
910 *
911 * The behavior of time-based autorotate is platform dependent. On platforms that allow you to query file creation time
912 * (e.g., Windows, macOS, BSD), the age of the file is calculated from its creation date. On platforms that don't keep
913 * track of file creation time (e.g., Linux), the age of the file is calculated using an internal timer that starts
914 * when the file is first opened. On such platforms, the age of the head log file is effectively reset to zero whenever
915 * you restart the process.
916 *
917 * \param[in] log logger object
918 * \param[in] log_file_path main log file to output (if relative path, interpreted relative to current working dir)
919 * \param[in] num_to_keep number of older rotated log files to keep on disk, or 0 to keep no old files
920 * \param[in] autorotate_size size (in bytes) after which the main log file is rotated, or 0 to disable size autorotate
921 * \param[in] autorotate_time_s time (in seconds) after which the main log file is rotated, or 0 to disable time autorotate
922 * \param[in] max_queue_bytes max size of queue used to buffer asynchronous writes to the log file
923 * \param[in] archive_cmd command used to compress old log files (e.g., "bzip2 -f"). If NULL, compression is disabled.
924 * \param[in] archive_file_ext extension added to files by \a archive_cmd (e.g., ".bz2"). If NULL, compression is disabled.
925 * \param[out] out_mod handle for created module, or \c NULL if there was an error.
926 * \return error code
927 */
928M_API M_log_error_t M_log_module_add_file(M_log_t *log, const char *log_file_path, size_t num_to_keep,
929 M_uint64 autorotate_size, M_uint64 autorotate_time_s, size_t max_queue_bytes, const char *archive_cmd,
930 const char *archive_file_ext, M_log_module_t **out_mod);
931
932
933/*! Manually trigger a file rotation.
934 *
935 * This can be used to rotate the main log file on some other condition than size - like receiving SIGHUP, or on
936 * some sort of timer. If the internal message queue is empty, the rotation will happen immediately. If not, the
937 * rotation will happen after the internal worker thread finishes writing the message it's currently working on.
938 *
939 * \param[in] log logger object
940 * \param[in] module handle of module to operate on
941 * \return error code
942 */
944
945/*! @} */ /* End of file group */
946
947
948
949
950/*! \addtogroup m_log_syslog Syslog Module
951 * \ingroup m_log
952 *
953 * Functions to enable logging to a local syslog server.
954 *
955 * Only available on some platforms.
956 *
957 * Note: syslog messages are limited to 1024 chars / line. Lines longer than this will be truncated.
958 *
959 * @{
960 */
961
962/*! Add a module to output to syslog (if supported by this platform).
963 *
964 * Note: syslog messages are limited to 1024 chars / line. Lines longer than this will be truncated.
965 *
966 * If the library wasn't compiled with syslog support, this function will return \link M_LOG_MODULE_UNSUPPORTED \endlink
967 * when called, and no module will be added to the logger.
968 *
969 * \param[in] log logger object
970 * \param[in] product short tag string passed to syslog: if \c NULL, will be set to program name
971 * \param[in] facility facility type to associate with all log messages, gets passed directly to syslog
972 * \param[in] max_queue_bytes max size of queue used to buffer asynchronous writes to syslog
973 * \param[out] out_mod handle for created module, or \c NULL if there was an error
974 * \return error code
975 */
976M_API M_log_error_t M_log_module_add_syslog(M_log_t *log, const char *product, M_syslog_facility_t facility,
977 size_t max_queue_bytes, M_log_module_t **out_mod);
978
979
980/*! Associate the given user-defined tag(s) with a syslog priority.
981 *
982 * If you don't associate a tag with a syslog priority, the default priority of \link M_SYSLOG_INFO \endlink will
983 * be used for that tag.
984 *
985 * \see M_LOG_ALL_TAGS
986 * \see M_log_all_tags_lt
987 * \see M_log_all_tags_lte
988 * \see M_log_all_tags_gt
989 * \see M_log_all_tags_gte
990 *
991 * \param[in] log logger object
992 * \param[in] module handle of module to operate on
993 * \param[in] tags user-defined power-of-two tag (or multiple power-of-two tags, OR'd together)
994 * \param[in] priority single priority value to associate with the given tags
995 * \return error code
996 */
998 M_syslog_priority_t priority);
999
1000/*! @} */ /* End of syslog group */
1001
1002
1003
1004
1005/*! \addtogroup m_log_tcp_syslog TCP Syslog Module
1006 * \ingroup m_log
1007 *
1008 * Functions to enable logging to a remote syslog server over TCP.
1009 *
1010 * This module formats messages according to the legacy BSD syslog format from RFC 3164, and adds
1011 * octet-counting framing as described in RFC 6587 for transmission over TCP. This legacy format was
1012 * chosen to ensure compatibility across a wide range of syslog servers.
1013 *
1014 * Messages are written asynchronously, as part of an existing event loop owned by the caller.
1015 *
1016 * Note: syslog messages are limited to 1024 chars / line. Lines longer than this will be truncated.
1017 *
1018 * @{
1019 */
1020
1021/*! Add a module to output to a remote syslog server over TCP.
1022 *
1023 * This module formats messages according to the legacy BSD syslog format from RFC 3164, and adds
1024 * octet-counting framing as described in RFC 6587 for transmission over TCP. This legacy format was
1025 * chosen to ensure compatibility across a wide range of syslog servers.
1026 *
1027 * Note: syslog messages are limited to 1024 chars / line. Lines longer than this will be truncated.
1028 *
1029 * \param[in] log logger object
1030 * \param[in] product short tag string for syslog, usually the name of the program sending log info
1031 * \param[in] facility facility type to associate with all log messages, gets passed directly to syslog
1032 * \param[in] host hostname of destination syslog server
1033 * \param[in] port port of destination syslog server (usually 514)
1034 * \param[in] dns external DNS resolver cache to use (not owned by logger)
1035 * \param[in] max_queue_bytes max size of queue used to buffer asynchronous writes to syslog
1036 * \param[out] out_mod handle for created module, or \c NULL if there was an error
1037 * \return error code
1038 */
1040 const char *host, M_uint16 port, M_dns_t *dns, size_t max_queue_bytes, M_log_module_t **out_mod);
1041
1042
1043/*! Set TCP connection timeout.
1044 *
1045 * Note that, in addition to normal connection parameters, the TCP module will automatically try to reconnect on
1046 * disconnect or error after a short delay, no matter what you set here.
1047 *
1048 * \param[in] log logger object
1049 * \param[in] module handle of module to operate on
1050 * \param[in] timeout_ms connection timeout, in milliseconds
1051 * \return error code
1052 */
1054 M_uint64 timeout_ms);
1055
1056
1057/*! Set TCP keep alive parameters for the connection.
1058 *
1059 * If this function isn't called, the following default values are used:
1060 * \li <tt>idle_time_s = 4 seconds</tt>
1061 * \li <tt>retry_time_s = 15 seconds</tt>
1062 * \li <tt>retry_count = 3</tt>
1063 *
1064 * \param[in] log logger object
1065 * \param[in] module handle of module to operate on
1066 * \param[in] idle_time_s tcp idle timeout, in seconds
1067 * \param[in] retry_time_s tcp retry time, in seconds
1068 * \param[in] retry_count tcp allowed number of retries
1069 * \return error code
1070 */
1072 M_uint64 retry_time_s, M_uint64 retry_count);
1073
1074
1075/*! Associate the given user-defined tag(s) with a syslog priority tag.
1076 *
1077 * If you don't associate a tag with a syslog priority, the default priority of \link M_SYSLOG_INFO \endlink will
1078 * be used for that tag.
1079 *
1080 * \see M_LOG_ALL_TAGS
1081 * \see M_log_all_tags_lt
1082 * \see M_log_all_tags_lte
1083 * \see M_log_all_tags_gt
1084 * \see M_log_all_tags_gte
1085 *
1086 * \param[in] log logger object
1087 * \param[in] module handle of module to operate on
1088 * \param[in] tags user-defined power-of-two tag (or multiple power-of-two tags, OR'd together)
1089 * \param[in] priority single priority value to associate with the given tags
1090 * \return error code
1091 */
1093 M_syslog_priority_t priority);
1094
1095/*! @} */ /* End of tcp_syslog group */
1096
1097
1098
1099
1100/*! \addtogroup m_log_membuf Memory Buffer Module
1101 * \ingroup m_log
1102 *
1103 * Functions to enable logging sensitive data to a temporary memory buffer.
1104 *
1105 * Membuf modules only accept messages until they are full, then they stop accepting messages and hang out in memory
1106 * until they're either explicitly retrieved by the caller with M_log_module_take_membuf(), or they reach their
1107 * expiration time and are automatically destroyed.
1108 *
1109 * @{
1110 */
1111
1112/*! Add a module to output to a buffer in memory.
1113 *
1114 * This is intended for temporary, in-memory storage of sensitive data that can't be stored long-term.
1115 *
1116 * Messages are accepted from the time the buffer is added, until the buffer is full. After that, no new messages
1117 * are stored, and the contents are preserved until either the module is removed, or the expiration time is reached.
1118 *
1119 * \param[in] log logger object
1120 * \param[in] buf_size max size (in bytes) of memory buffer
1121 * \param[in] buf_time_s max time (in seconds) to allow buffer to exist in memory before it's automatically deleted
1122 * \param[in] expire_cb callback to call when a memory buffer is automatically deleted
1123 * \param[in] expire_thunk any state used by the expire callback (not owned by log, you must delete it yourself)
1124 * \param[out] out_mod handle for created module, or \c NULL if there was an error
1125 * \return error code
1126 */
1127M_API M_log_error_t M_log_module_add_membuf(M_log_t *log, size_t buf_size, M_uint64 buf_time_s,
1128 M_log_expire_cb expire_cb, void *expire_thunk, M_log_module_t **out_mod);
1129
1130
1131/*! Remove a membuf module from the log and return the internal memory store.
1132 *
1133 * This method should be used if you need to preserve the data stored in the buffer. If you just want
1134 * to remove the module and you don't care about the memory buffer contents, you should call the normal
1135 * M_log_module_remove() function instead.
1136 *
1137 * \see M_log_module_remove
1138 *
1139 * \param[in] log logger object
1140 * \param[in] module handle of module to operate on
1141 * \param[out] out_buf buffer containing membuf data, or \c NULL if there was an error
1142 * \return error code
1143 */
1145
1146/*! @} */ /* End of membuf group */
1147
1148
1149
1150__END_DECLS
1151
1152#endif /* M_LOG_H */
struct M_buf M_buf_t
Definition: m_buf.h:77
struct M_dns M_dns_t
Definition: m_dns.h:43
struct M_event M_event_t
Definition: m_event.h:210
struct M_list M_list_t
Definition: m_list.h:92
M_log_error_t M_log_module_android_set_tag_priority(M_log_t *log, M_log_module_t *module, M_uint64 tags, M_android_log_priority_t priority)
M_log_error_t M_log_module_add_android(M_log_t *log, const char *product, size_t max_queue_bytes, M_log_module_t **out_mod)
M_log_module_type_t
Definition: m_log.h:229
M_log_error_t M_log_set_time_format(M_log_t *log, const char *fmt)
M_log_error_t M_log_set_tag_name(M_log_t *log, M_uint64 tag, const char *name)
M_log_error_t M_log_set_prefix(M_log_t *log, M_log_prefix_cb prefix_cb, void *prefix_thunk, M_log_destroy_cb thunk_destroy_cb)
M_log_error_t M_log_module_set_accepted_tags(M_log_t *log, M_log_module_t *module, M_uint64 tags)
M_bool M_log_module_present(M_log_t *log, M_log_module_t *module)
M_log_line_end_mode_t
Definition: m_log.h:242
void(* M_log_prefix_cb)(M_buf_t *msg_buf, M_uint64 tag, void *prefix_thunk, void *msg_thunk)
Definition: m_log.h:159
M_log_error_t M_log_module_set_prefix(M_log_t *log, M_log_module_t *module, M_log_prefix_cb prefix_cb, void *prefix_thunk, M_log_destroy_cb thunk_destroy_cb)
void(* M_log_destroy_cb)(void *thunk)
Definition: m_log.h:206
M_log_error_t M_log_module_remove(M_log_t *log, M_log_module_t *module)
void M_log_suspend(M_log_t *log)
const char * M_log_err_to_str(M_log_error_t err)
M_android_log_priority_t
Definition: m_log.h:299
M_list_t * M_log_all_modules(M_log_t *log)
M_log_error_t M_log_module_get_accepted_tags(M_log_t *log, M_log_module_t *module, M_uint64 *out_tags)
const char * M_log_get_tag_name(M_log_t *log, M_uint64 tag)
void M_log_emergency(M_log_t *log, const char *msg)
M_log_error_t M_log_set_tag_names_padded(M_log_t *log, M_bool padded)
void M_log_destroy_blocking(M_log_t *log, M_uint64 timeout_ms)
void M_log_reopen_all(M_log_t *log)
void M_log_resume(M_log_t *log, M_event_t *event)
M_log_error_t M_log_module_set_filter(M_log_t *log, M_log_module_t *module, M_log_filter_cb filter_cb, void *filter_thunk, M_log_destroy_cb thunk_destroy_cb)
struct M_log_module M_log_module_t
Definition: m_log.h:126
M_log_error_t M_log_write(M_log_t *log, M_uint64 tag, void *msg_thunk, const char *msg)
M_stream_type_t
Definition: m_log.h:250
M_uint64 M_log_get_tag(M_log_t *log, const char *name)
M_log_error_t
Definition: m_log.h:210
M_log_error_t M_log_vprintf(M_log_t *log, M_uint64 tag, void *msg_thunk, const char *fmt, va_list ap)
void(* M_log_expire_cb)(M_log_module_t *module, void *thunk)
Definition: m_log.h:202
M_log_error_t M_log_module_reopen(M_log_t *log, M_log_module_t *module)
struct M_log M_log_t
Definition: m_log.h:122
void M_log_destroy(M_log_t *log)
M_syslog_priority_t
Definition: m_log.h:281
M_syslog_facility_t
Definition: m_log.h:257
M_bool(* M_log_filter_cb)(M_uint64 tag, void *filter_thunk, void *msg_thunk)
Definition: m_log.h:181
M_log_error_t M_log_printf(M_log_t *log, M_uint64 tag, void *msg_thunk, const char *fmt,...)
M_log_t * M_log_create(M_log_line_end_mode_t mode, M_bool flush_on_destroy, M_event_t *event)
M_log_module_type_t M_log_module_type(M_log_t *log, M_log_module_t *module)
@ M_LOG_MODULE_MEMBUF
Definition: m_log.h:237
@ M_LOG_MODULE_NSLOG
Definition: m_log.h:232
@ M_LOG_MODULE_STREAM
Definition: m_log.h:231
@ M_LOG_MODULE_ANDROID
Definition: m_log.h:233
@ M_LOG_MODULE_NULL
Definition: m_log.h:230
@ M_LOG_MODULE_FILE
Definition: m_log.h:234
@ M_LOG_MODULE_SYSLOG
Definition: m_log.h:235
@ M_LOG_MODULE_TSYSLOG
Definition: m_log.h:236
@ M_LOG_LINE_END_UNIX
Definition: m_log.h:244
@ M_LOG_LINE_END_WINDOWS
Definition: m_log.h:245
@ M_LOG_LINE_END_NATIVE
Definition: m_log.h:243
@ M_ANDROID_LOG_ERROR
Definition: m_log.h:301
@ M_ANDROID_LOG_INFO
Definition: m_log.h:303
@ M_ANDROID_LOG_FATAL
Definition: m_log.h:300
@ M_ANDROID_LOG_WARN
Definition: m_log.h:302
@ M_ANDROID_LOG_DEBUG
Definition: m_log.h:304
@ M_ANDROID_LOG_VERBOSE
Definition: m_log.h:305
@ M_STREAM_STDERR
Definition: m_log.h:252
@ M_STREAM_STDOUT
Definition: m_log.h:251
@ M_LOG_MODULE_NOT_FOUND
Definition: m_log.h:222
@ M_LOG_WRONG_MODULE
Definition: m_log.h:223
@ M_LOG_INVALID_PARAMS
Definition: m_log.h:213
@ M_LOG_INVALID_TAG
Definition: m_log.h:215
@ M_LOG_MODULE_UNSUPPORTED
Definition: m_log.h:221
@ M_LOG_UNREACHABLE
Definition: m_log.h:219
@ M_LOG_SUSPENDED
Definition: m_log.h:217
@ M_LOG_INVALID_PATH
Definition: m_log.h:214
@ M_LOG_NO_EVENT_LOOP
Definition: m_log.h:216
@ M_LOG_GENERIC_FAIL
Definition: m_log.h:224
@ M_LOG_INVALID_TIME_FORMAT
Definition: m_log.h:220
@ M_LOG_DUPLICATE_TAG_NAME
Definition: m_log.h:218
@ M_LOG_SUCCESS
Definition: m_log.h:211
@ M_SYSLOG_WARNING
Definition: m_log.h:286
@ M_SYSLOG_NOTICE
Definition: m_log.h:287
@ M_SYSLOG_EMERG
Definition: m_log.h:282
@ M_SYSLOG_CRIT
Definition: m_log.h:284
@ M_SYSLOG_ALERT
Definition: m_log.h:283
@ M_SYSLOG_DEBUG
Definition: m_log.h:289
@ M_SYSLOG_ERR
Definition: m_log.h:285
@ M_SYSLOG_INFO
Definition: m_log.h:288
@ M_SYSLOG_FACILITY_USER
Definition: m_log.h:258
@ M_SYSLOG_FACILITY_LOCAL3
Definition: m_log.h:263
@ M_SYSLOG_FACILITY_LOCAL5
Definition: m_log.h:265
@ M_SYSLOG_FACILITY_DAEMON
Definition: m_log.h:259
@ M_SYSLOG_FACILITY_LOCAL2
Definition: m_log.h:262
@ M_SYSLOG_FACILITY_LOCAL1
Definition: m_log.h:261
@ M_SYSLOG_FACILITY_LOCAL4
Definition: m_log.h:264
@ M_SYSLOG_FACILITY_LOCAL0
Definition: m_log.h:260
@ M_SYSLOG_FACILITY_LOCAL6
Definition: m_log.h:266
@ M_SYSLOG_FACILITY_LOCAL7
Definition: m_log.h:267
M_log_error_t M_log_module_file_rotate(M_log_t *log, M_log_module_t *module)
M_log_error_t M_log_module_add_file(M_log_t *log, const char *log_file_path, size_t num_to_keep, M_uint64 autorotate_size, M_uint64 autorotate_time_s, size_t max_queue_bytes, const char *archive_cmd, const char *archive_file_ext, M_log_module_t **out_mod)
M_log_error_t M_log_module_add_membuf(M_log_t *log, size_t buf_size, M_uint64 buf_time_s, M_log_expire_cb expire_cb, void *expire_thunk, M_log_module_t **out_mod)
M_log_error_t M_log_module_take_membuf(M_log_t *log, M_log_module_t *module, M_buf_t **out_buf)
M_log_error_t M_log_module_add_nslog(M_log_t *log, size_t max_queue_bytes, M_log_module_t **out_mod)
M_log_error_t M_log_module_add_stream(M_log_t *log, M_stream_type_t type, size_t max_queue_bytes, M_log_module_t **out_mod)
M_log_error_t M_log_module_syslog_set_tag_priority(M_log_t *log, M_log_module_t *module, M_uint64 tags, M_syslog_priority_t priority)
M_log_error_t M_log_module_add_syslog(M_log_t *log, const char *product, M_syslog_facility_t facility, size_t max_queue_bytes, M_log_module_t **out_mod)
M_uint64 M_log_all_tags_gt(M_uint64 tag)
M_uint64 M_log_all_tags_lt(M_uint64 tag)
M_uint64 M_log_all_tags_lte(M_uint64 tag)
M_uint64 M_log_all_tags_gte(M_uint64 tag)
M_log_error_t M_log_module_add_tcp_syslog(M_log_t *log, const char *product, M_syslog_facility_t facility, const char *host, M_uint16 port, M_dns_t *dns, size_t max_queue_bytes, M_log_module_t **out_mod)
M_log_error_t M_log_module_tcp_syslog_set_keepalives(M_log_t *log, M_log_module_t *module, M_uint64 idle_time_s, M_uint64 retry_time_s, M_uint64 retry_count)
M_log_error_t M_log_module_tcp_syslog_set_connect_timeout_ms(M_log_t *log, M_log_module_t *module, M_uint64 timeout_ms)
M_log_error_t M_log_module_tcp_syslog_set_tag_priority(M_log_t *log, M_log_module_t *module, M_uint64 tags, M_syslog_priority_t priority)