Debian Codegraph @

libdrgn/log.h

raw
1 // Copyright (c) Meta Platforms, Inc. and affiliates.
2 // SPDX-License-Identifier: LGPL-2.1-or-later
3
4 /**
5 * @file
6 *
7 * Logging.
8 *
9 * See @ref LoggingInternals.
10 */
11
12 #ifndef DRGN_LOG_H
13 #define DRGN_LOG_H
14
15 #include "drgn_internal.h"
16
17 /**
18 * @ingroup Internals
19 *
20 * @defgroup LoggingInternals Logging
21 *
22 * Logging functions.
23 *
24 * @{
25 */
26
27 /**
28 * Return whether the given log level is enabled.
29 *
30 * This can be used to avoid expensive computations that are only needed for
31 * logging.
32 */
33 bool drgn_log_is_enabled(struct drgn_program *prog, enum drgn_log_level level);
34
35 /**
36 * @{
37 *
38 * @name Logging Functions
39 */
40
41 #ifdef DOXYGEN
42 /** Log a printf-style message at the given level. */
43 void drgn_log(enum drgn_log_level level, struct drgn_program *prog,
44 const char *format, ...);
45 #else
46 #define drgn_log(level, prog, ...) drgn_error_log(level, prog, NULL, __VA_ARGS__)
47 #endif
48 /** Log a critical message. */
49 #define drgn_log_critical(...) drgn_log(DRGN_LOG_CRITICAL, __VA_ARGS__)
50 /** Log an error message. */
51 #define drgn_log_error(...) drgn_log(DRGN_LOG_ERROR, __VA_ARGS__)
52 /** Log a warning message. */
53 #define drgn_log_warning(...) drgn_log(DRGN_LOG_WARNING, __VA_ARGS__)
54 /** Log an informational message. */
55 #define drgn_log_info(...) drgn_log(DRGN_LOG_INFO, __VA_ARGS__)
56 /** Log a debug message. */
57 #define drgn_log_debug(...) drgn_log(DRGN_LOG_DEBUG, __VA_ARGS__)
58
59 /**
60 * @}
61 *
62 * @{
63 *
64 * @name Error Logging Functions
65 */
66
67 /**
68 * Log a printf-style message followed by a @ref drgn_error at the given level.
69 */
70 __attribute__((__format__(__printf__, 4, 5), __nonnull__(2, 4)))
71 void drgn_error_log(enum drgn_log_level level, struct drgn_program *prog,
72 struct drgn_error *err, const char *format, ...);
73 /** Log a critical message followed by a @ref drgn_error. */
74 #define drgn_error_log_critical(...) drgn_error_log(DRGN_LOG_CRITICAL, __VA_ARGS__)
75 /** Log an error message followed by a @ref drgn_error. */
76 #define drgn_error_log_error(...) drgn_error_log(DRGN_LOG_ERROR, __VA_ARGS__)
77 /** Log a warning message followed by a @ref drgn_error. */
78 #define drgn_error_log_warning(...) drgn_error_log(DRGN_LOG_WARNING, __VA_ARGS__)
79 /** Log an informational message followed by a @ref drgn_error. */
80 #define drgn_error_log_info(...) drgn_error_log(DRGN_LOG_INFO, __VA_ARGS__)
81 /** Log a debug message followed by a @ref drgn_error. */
82 #define drgn_error_log_debug(...) drgn_error_log(DRGN_LOG_DEBUG, __VA_ARGS__)
83
84 /**
85 * @}
86 * @}
87 */
88
89 FILE *drgn_program_get_progress_file(struct drgn_program *prog,
90 int *columns_ret);
91
92 #endif /* DRGN_LOG_H */