96cc10bd4589b65f84ede8294383591163de2dce
2 * Copyright (C) 2011 EfficiOS Inc.
4 * SPDX-License-Identifier: GPL-2.0-only
16 #include <urcu/tls-compat.h>
17 #include <common/compat/time.h>
20 #error "lttng-tools error.h needs _GNU_SOURCE"
23 #include <lttng/lttng-error.h>
24 #include <common/compat/tid.h>
26 /* Avoid conflict with Solaris <sys/regset.h> */
27 #if defined(ERR) && defined(__sun__)
31 /* Stringify the expansion of a define */
32 #define XSTR(d) STR(d)
36 * Contains the string of the log entry time. This is used as a thread local
37 * storage so we don't race between thread and also avoid memory allocation
38 * every time a log is fired.
41 /* Format: 00:00:00.000000000 plus NULL byte. */
44 extern DECLARE_URCU_TLS(struct log_time
, error_log_time
);
46 extern int lttng_opt_quiet
;
47 extern int lttng_opt_verbose
;
48 extern int lttng_opt_mi
;
51 enum lttng_error_level
{
61 static inline bool __lttng_print_check_opt(enum lttng_error_level type
)
63 /* lttng_opt_mi and lttng_opt_quiet. */
76 if (lttng_opt_quiet
) {
81 /* lttng_opt_verbose */
84 if (lttng_opt_verbose
< 3) {
89 if (lttng_opt_verbose
< 2) {
94 if (lttng_opt_verbose
< 1) {
108 void lttng_abort_on_error(void);
110 static inline void __lttng_print_check_abort(enum lttng_error_level type
)
121 lttng_abort_on_error();
126 * Macro for printing message depending on command line option and verbosity.
129 * We use lttng_opt_mi to suppress all normal msg to stdout. We don't
130 * want any nested msg to show up when printing mi to stdout(if it's the case).
131 * All warnings and errors should be printed to stderr as normal.
133 #define __lttng_print(type, fmt, args...) \
135 if (__lttng_print_check_opt(type)) { \
136 fprintf((type) == PRINT_MSG ? stdout : stderr, fmt, ## args); \
138 __lttng_print_check_abort(type); \
141 /* Three level of debug. Use -v, -vv or -vvv for the levels */
142 #define _ERRMSG(msg, type, fmt, args...) __lttng_print(type, msg \
143 " - %s [%ld/%ld]: " fmt " (in %s() at " __FILE__ ":" XSTR(__LINE__) ")\n", \
144 log_add_time(), (long) getpid(), (long) lttng_gettid(), ## args, __func__)
146 #define _ERRMSG_NO_LOC(msg, type, fmt, args...) __lttng_print(type, msg \
147 " - %s [%ld/%ld]: " fmt "\n", \
148 log_add_time(), (long) getpid(), (long) lttng_gettid(), ## args)
150 #define MSG(fmt, args...) \
151 __lttng_print(PRINT_MSG, fmt "\n", ## args)
152 #define _MSG(fmt, args...) \
153 __lttng_print(PRINT_MSG, fmt, ## args)
154 #define ERR(fmt, args...) \
155 __lttng_print(PRINT_ERR, "Error: " fmt "\n", ## args)
156 #define WARN(fmt, args...) \
157 __lttng_print(PRINT_WARN, "Warning: " fmt "\n", ## args)
159 #define BUG(fmt, args...) _ERRMSG("BUG", PRINT_BUG, fmt, ## args)
161 #define DBG(fmt, args...) _ERRMSG("DEBUG1", PRINT_DBG, fmt, ## args)
162 #define DBG_NO_LOC(fmt, args...) _ERRMSG_NO_LOC("DEBUG1", PRINT_DBG, fmt, ## args)
163 #define DBG2(fmt, args...) _ERRMSG("DEBUG2", PRINT_DBG2, fmt, ## args)
164 #define DBG3(fmt, args...) _ERRMSG("DEBUG3", PRINT_DBG3, fmt, ## args)
165 #define LOG(type, fmt, args...) \
172 WARN(fmt, ## args); \
184 DBG2(fmt, ## args); \
187 DBG3(fmt, ## args); \
194 #define _PERROR(fmt, args...) _ERRMSG("PERROR", PRINT_ERR, fmt, ## args)
196 #if !defined(__GLIBC__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
199 * Version using XSI strerror_r.
201 #define PERROR(call, args...) \
204 strerror_r(errno, buf, sizeof(buf)); \
205 _PERROR(call ": %s", ## args, buf); \
209 * Version using GNU strerror_r, for linux with appropriate defines.
211 #define PERROR(call, args...) \
215 buf = strerror_r(errno, tmp, sizeof(tmp)); \
216 _PERROR(call ": %s", ## args, buf); \
220 const char *error_get_str(int32_t code
);
223 * Function that format the time and return the reference of log_time.str to
224 * the caller. On error, an empty string is returned thus no time will be
225 * printed in the log.
227 const char *log_add_time(void);
229 #endif /* _ERROR_H */
This page took 0.034605 seconds and 4 git commands to generate.