8#ifndef LOGGING_INCLUDE_LOGGING_DETAIL_LOGGER_HXX_
9#define LOGGING_INCLUDE_LOGGING_DETAIL_LOGGER_HXX_
17#if defined(__has_feature)
18# if __has_feature(thread_sanitizer)
19__attribute__((no_sanitize(
"thread")))
22static void verstrace_user(
struct timeval *,
int TID, uint8_t lvl,
const char* insert
23 ,
const char* file,
int line,
const char* function, uint16_t nargs,
const char *msg, va_list ap)
29 char obuf[TRACE_USER_MSGMAX];
31 if ((insert && (printed = strlen(insert))) || nargs)
36 retval = snprintf(obuf,
sizeof(obuf),
"%s ",insert );
37 printed = TRACE_SNPRINTED(retval,
sizeof(obuf));
40 retval = vsnprintf(&(obuf[printed]),
sizeof(obuf) - printed, msg, ap);
41 printed += TRACE_SNPRINTED(retval,
sizeof(obuf)-printed);
45 retval = snprintf( &(obuf[printed]),
sizeof(obuf)-printed,
"%s", msg );
46 printed += TRACE_SNPRINTED(retval,
sizeof(obuf)-printed);
48 if (obuf[printed-1] ==
'\n')
49 obuf[printed-1] =
'\0';
52 if (msg[strlen(msg)-1] ==
'\n') {
53 retval = snprintf( obuf,
sizeof(obuf),
"%s", msg );
54 printed = TRACE_SNPRINTED(retval,
sizeof(obuf));
55 if (obuf[printed-1] ==
'\n')
56 obuf[printed-1] =
'\0';
63 reinterpret_cast<char*
>(idx2namsPtr(TID)),
64 file, line, function, DEBUG_FORCED );
67 if (lvl < TLVL_DEBUG) {
72 ers::log( ers::InternalMessage(lc,outp) );
74 ers::debug( ers::InternalMessage(lc,outp),lvl-TLVL_DEBUG );
79static 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, ...)
83 verstrace_user(tvp, TID, lvl, insert, file, line, function, nargs, msg, ap);
87#pragma GCC diagnostic push
88#pragma GCC diagnostic ignored "-Wvarargs"
90static 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 std::string& msg, ...)
94 verstrace_user(tvp, TID, lvl, insert, file, line, function, nargs, &msg[0], ap);
97#pragma GCC diagnostic pop
105 x.line_ = r.context().line_number();
106 x.msg_append(r.message().c_str());
114 else if (x.lvl_==TLVL_LOG)
ers::log( r ); \
120inline void operator<<(TraceStreamer& x,
const ers::InternalMessage &r)
123 x.line_ = r.context().line_number();
124 x.msg_append(r.message().c_str());
129 else if (x.lvl_==TLVL_LOG)
ers::log( r ); \
138 class ErsFatalStreamer
148 class ErsErrorStreamer
158 class ErsWarningStreamer
170 class ErsInfoStreamer
207 uint8_t lvl_=TLVL_DEBUG;
210 case ers::Log: lvl_=TLVL_LOG;
break;
216 struct {
char tn[TRACE_TN_BUFSZ]; } _trc_;
218 if (traceControl_rwp->mode.bits.M && (traceLvls_p[traceTID].M & TLVLMSK(lvl_))) {
219 struct timeval lclTime;
220 std::chrono::system_clock::time_point tp{issue.
ptime()};
222 std::chrono::microseconds micros = std::chrono::duration_cast<std::chrono::microseconds>(tp.time_since_epoch());
223 lclTime.tv_sec = micros.count() / 1000000;
224 lclTime.tv_usec = micros.count() % 1000000;
226 std::string complete_message = issue.
message();
228 while ((issp=issp->
cause())) {
229 char fbuf[0x100], tbuf[0x40];
232 std::chrono::milliseconds millis
233 = std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch());
235 time_t secs = millis.count() / 1000;
236 localtime_r(&secs, &tm_s);
237 if (strftime(tbuf,
sizeof(tbuf),
"%Y-%b-%d %H:%M:%S", &tm_s) == 0)
239 complete_message +=
"\n\tcaused by: " + std::string(tbuf);
240 int milliseconds = millis.count() % 1000;
241 sprintf(tbuf,
",%03d ",milliseconds);
242 complete_message += std::string(tbuf);
245 +
" [" + fbuf +
" at "
252 0 TRACE_XTRA_PASSED, complete_message.c_str());
263#define SL_FRC(lvl) ((lvl)>=0 && (lvl)<TLVL_DEBUG)
266#define LOG1_(value) value,
267#define LOG2_(value, value1) value , value1,
268#define COMMA_IF_PARENS(...) ,
270#define EXPAND_(...) __VA_ARGS__
271#define CHOOSE_(...) EXPAND_(LOG__ LPAREN \
272 __VA_ARGS__ COMMA_IF_PARENS __VA_ARGS__ COMMA_IF_PARENS __VA_ARGS__ (), \
273 LOG2_, impossible, LOG2_, LOG1_, LOG0_, LOG1_, ))
274#define LOG__(a0, a1, a2, a3, a4, a5, arg, ...) arg
275#define _tlog_ARG2( a1,a2,...) tlog_ARG2(a1,a2,__VA_ARGS__)
276#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
ERS abstract output stream interface.
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)