Skip to content

Commit efcad31

Browse files
committed
Add timestamp switch
1 parent 7d86dea commit efcad31

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/apps/weblib/interface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Interface Interface::instance;
1717
Interface::Interface() : versionStr(std::string(Main::version))
1818
{
1919
IO::Log::setEnabled(false);
20+
IO::Log::setTimestamp(false);
2021
needsUpdate = false;
2122
eventParam = nullptr;
2223
}

src/base/io/log.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,34 @@ using namespace IO;
77
namespace
88
{
99
static bool enabled = true;
10+
static bool timestamp = true;
1011
static Log::LogFunc logFunc = [](std::string const &s)
1112
{
1213
puts(s.c_str());
1314
};
1415

1516
}
1617

17-
LogRecord::LogRecord() : content("[vizzu] [YYYY-mm-ddTHH:MM:SSZ] ")
18+
LogRecord::LogRecord() : content("[vizzu] ")
1819
{
19-
std::time_t now;
20-
std::time(&now);
21-
std::strftime(content.data() + 9,
22-
21,
23-
"%Y-%m-%dT%H:%M:%SZ",
24-
std::gmtime(&now));
25-
content[9 + 20] = ']';
20+
if (timestamp) {
21+
content += "[YYYY-mm-ddTHH:MM:SSZ] ";
22+
std::time_t now;
23+
std::time(&now);
24+
std::strftime(content.data() + 9,
25+
21,
26+
"%Y-%m-%dT%H:%M:%SZ",
27+
std::gmtime(&now));
28+
content[9 + 20] = ']';
29+
}
2630
}
2731

2832
void Log::set(Log::LogFunc f) { logFunc = std::move(f); }
2933

3034
void Log::setEnabled(bool value) { enabled = value; }
3135

36+
void Log::setTimestamp(bool value) { timestamp = value; }
37+
3238
void Log::print(const std::string &msg)
3339
{
3440
if (logFunc) logFunc(msg);

src/base/io/log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Log
1717
typedef std::function<void(const std::string &)> LogFunc;
1818
static void set(LogFunc f);
1919
static void setEnabled(bool);
20+
static void setTimestamp(bool);
2021

2122
private:
2223
static void print(const std::string &msg);

0 commit comments

Comments
 (0)