1
0
mirror of https://github.com/Zygo/bees.git synced 2025-06-16 09:36:17 +02:00

Add option for prefixing timestamps

To make bees more friendly to use with syslog/systemd, we add an option
to omit timestamps from the log output.

Signed-off-by: Kai Krakow <kai@kaishome.de>
This commit is contained in:
Kai Krakow
2017-10-27 23:02:47 +02:00
parent c6bf6bfe1d
commit c6be07e158
4 changed files with 41 additions and 25 deletions

View File

@ -17,6 +17,7 @@ namespace crucible {
static shared_ptr<set<string>> chatter_names;
static const char *SPACETAB = " \t";
static int chatter_prefix_timestamp = 1;
static
void
@ -52,16 +53,21 @@ namespace crucible {
{
ostringstream header_stream;
time_t ltime;
DIE_IF_MINUS_ONE(time(&ltime));
struct tm ltm;
DIE_IF_ZERO(localtime_r(&ltime, &ltm));
if (chatter_prefix_timestamp) {
time_t ltime;
DIE_IF_MINUS_ONE(time(&ltime));
struct tm ltm;
DIE_IF_ZERO(localtime_r(&ltime, &ltm));
char buf[1024];
DIE_IF_ZERO(strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &ltm));
char buf[1024];
DIE_IF_ZERO(strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &ltm));
header_stream << buf;
header_stream << " " << getpid() << "." << gettid();
} else {
header_stream << "tid " << gettid();
}
header_stream << buf;
header_stream << " " << getpid() << "." << gettid();
if (!m_name.empty()) {
header_stream << " " << m_name;
}
@ -91,6 +97,11 @@ namespace crucible {
c.m_oss.str("");
}
ChatterTimestamp::ChatterTimestamp(int prefix_timestamp)
{
chatter_prefix_timestamp = prefix_timestamp;
}
set<ChatterBox*> ChatterBox::s_boxes;
set<ChatterBox*>& ChatterBox::all_boxes()