8#ifndef LOGGING_INCLUDE_LOGGING_DETAIL_LOGGER_HXX_
9#define LOGGING_INCLUDE_LOGGING_DETAIL_LOGGER_HXX_
16#if defined(__has_feature)
17#if __has_feature(thread_sanitizer)
18__attribute__((no_sanitize(
"thread")))
37 char obuf[TRACE_USER_MSGMAX];
39 if ((insert && (printed = strlen(insert))) || nargs) {
43 retval = snprintf(obuf,
sizeof(obuf),
"%s ", insert);
44 printed = TRACE_SNPRINTED(retval,
sizeof(obuf));
48 vsnprintf(&(obuf[printed]),
sizeof(obuf) - printed, msg, ap);
49 printed += TRACE_SNPRINTED(retval,
sizeof(obuf) - printed);
53 retval = snprintf(&(obuf[printed]),
sizeof(obuf) - printed,
"%s", msg);
54 printed += TRACE_SNPRINTED(retval,
sizeof(obuf) - printed);
56 if (obuf[printed - 1] ==
'\n')
57 obuf[printed - 1] =
'\0';
60 if (msg[strlen(msg) - 1] ==
'\n') {
61 retval = snprintf(obuf,
sizeof(obuf),
"%s", msg);
62 printed = TRACE_SNPRINTED(retval,
sizeof(obuf));
63 if (obuf[printed - 1] ==
'\n')
64 obuf[printed - 1] =
'\0';
70 ers::LocalContext lc(
reinterpret_cast<char*
>(idx2namsPtr(TID)), file, line, function, DEBUG_FORCED);
73 if (lvl < TLVL_DEBUG) {
79 ers::log(ers::InternalMessage(lc, outp));
81 ers::debug(ers::InternalMessage(lc, outp), lvl - TLVL_DEBUG);
100 verstrace_user(tvp, TID, lvl, insert, file, line, function, nargs, msg, ap);
104#pragma GCC diagnostic push
105#pragma GCC diagnostic ignored "-Wvarargs"
106SUPPRESS_NOT_USED_WARN
114 const char* function,
116 const std::string& msg,
121 verstrace_user(tvp, TID, lvl, insert, file, line, function, nargs, &msg[0], ap);
124#pragma GCC diagnostic pop
131 x.line_ = r.context().line_number();
132 x.msg_append(r.message().c_str());
139 if (x.lvl_ == TLVL_INFO)
141 else if (x.lvl_ == TLVL_LOG)
150operator<<(TraceStreamer& x,
const ers::InternalMessage& r)
153 x.line_ = r.context().line_number();
154 x.msg_append(r.message().c_str());
158 if (x.lvl_ == TLVL_INFO)
160 else if (x.lvl_ == TLVL_LOG)
170class ErsFatalStreamer
173 inline ErsFatalStreamer&
operator<<(
const ers::Issue& r)
180class ErsErrorStreamer
183 inline ErsErrorStreamer&
operator<<(
const ers::Issue& r)
190class ErsWarningStreamer
195 inline ErsWarningStreamer&
operator<<(
const ers::Issue& r)
207 inline ErsInfoStreamer&
operator<<(
const ers::Issue& r)
219 inline ErsLogStreamer&
operator<<(
const ers::Issue& r)
237 uint8_t lvl_ = TLVL_DEBUG;
240 lvl_ = TLVL_DEBUG + sev.
rank;
260 char tn[TRACE_TN_BUFSZ];
263 if (traceControl_rwp->mode.bits.M && (traceLvls_p[traceTID].M & TLVLMSK(lvl_))) {
264 struct timeval lclTime;
265 std::chrono::system_clock::time_point tp{ issue.
ptime() };
267 std::chrono::microseconds micros = std::chrono::duration_cast<std::chrono::microseconds>(tp.time_since_epoch());
268 lclTime.tv_sec = micros.count() / 1000000;
269 lclTime.tv_usec = micros.count() % 1000000;
271 std::string complete_message = issue.
message();
273 while ((issp = issp->
cause())) {
274 char fbuf[0x100], tbuf[0x40];
277 std::chrono::milliseconds millis =
278 std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch());
280 time_t secs = millis.count() / 1000;
281 localtime_r(&secs, &tm_s);
282 if (strftime(tbuf,
sizeof(tbuf),
"%Y-%b-%d %H:%M:%S", &tm_s) == 0)
284 complete_message +=
"\n\tcaused by: " + std::string(tbuf);
285 int milliseconds = millis.count() % 1000;
286 sprintf(tbuf,
",%03d ", milliseconds);
287 complete_message += std::string(tbuf);
299 complete_message.c_str());
309#define SL_FRC(lvl) ((lvl) >= 0 && (lvl) < TLVL_DEBUG)
312#define LOG1_(value) value,
313#define LOG2_(value, value1) value, value1,
314#define COMMA_IF_PARENS(...) ,
316#define EXPAND_(...) __VA_ARGS__
317#define CHOOSE_(...) EXPAND_(LOG__ LPAREN \
318 __VA_ARGS__ COMMA_IF_PARENS __VA_ARGS__ COMMA_IF_PARENS __VA_ARGS__ (), \
319 LOG2_, impossible, LOG2_, LOG1_, LOG0_, LOG1_, ))
320#define LOG__(a0, a1, a2, a3, a4, a5, arg, ...) arg
321#define _tlog_ARG2(a1, a2, ...) tlog_ARG2(a1, a2, __VA_ARGS__)
322#define _tlog_ARG3(a1, a2, a3, ...) tlog_ARG3(a1, a2, a3, __VA_ARGS__)
static void verstrace_user(struct timeval *, int TID, uint8_t lvl, const char *insert, const char *file, int line, const char *function, uint16_t nargs, const char *msg, va_list ap)
static SUPPRESS_NOT_USED_WARN void erstrace_user(struct timeval *tvp, int TID, uint8_t lvl, const char *insert, const char *file, int line, const char *function, uint16_t nargs, const char *msg,...)
void operator<<(TraceStreamer &x, const ers::Issue &r)
virtual int line_number() const =0
virtual const char * file_name() const =0
virtual const char * function_name() const =0
Base class for any user define issue.
const Context & context() const
Context of the issue.
ers::Severity severity() const
severity of the issue
const system_clock::time_point & ptime() const
original time point of the issue
const std::string & message() const
General cause of the issue.
const Issue * cause() const
return the cause Issue of this Issue
virtual void write(const Issue &issue)=0
#define ERS_REGISTER_OUTPUT_STREAM(class, name, param)
void warning(const Issue &issue)
void info(const Issue &issue)
void log(const Issue &issue)
std::string to_string(severity s)
void debug(const Issue &issue, int level=debug_level())
void fatal(const Issue &issue)
void error(const Issue &issue)
void write(const ers::Issue &issue)