Split bond logs into two categories to reduce logging size

This commit is contained in:
Joseph Henry 2022-01-26 15:14:02 -08:00
parent 60057d7072
commit 46e955e3a1
No known key found for this signature in database
GPG key ID: C45B33FF5EBC9344
2 changed files with 63 additions and 33 deletions

View file

@ -1159,6 +1159,36 @@ class Bond {
va_end(args);
RR->t->bondStateMessage(NULL, traceMsg);
#undef MAX_MSG_LEN
#endif
}
/**
* Emit message to tracing system but with added timestamp and subsystem info
*
* TODO: Will be replaced when better logging facilities exist in Trace.hpp
*/
void debug(const char* fmt, ...)
{
#ifdef ZT_DEBUG
time_t rawtime;
struct tm* timeinfo;
char timestamp[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(timestamp, 80, "%F %T", timeinfo);
#define MAX_BOND_MSG_LEN 1024
char traceMsg[MAX_BOND_MSG_LEN];
char userMsg[MAX_BOND_MSG_LEN];
va_list args;
va_start(args, fmt);
if (vsnprintf(userMsg, sizeof(userMsg), fmt, args) < 0) {
fprintf(stderr, "Encountered format encoding error while writing to trace log\n");
return;
}
snprintf(traceMsg, MAX_BOND_MSG_LEN, "%s (%llx/%s) %s", timestamp, _peerId, _policyAlias.c_str(), userMsg);
va_end(args);
RR->t->bondStateMessage(NULL, traceMsg);
#undef MAX_MSG_LEN
#endif
}