diff options
author | Alex Zolotarev <alex@maps.me> | 2015-07-03 20:25:55 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:54:34 +0300 |
commit | 6360ff5238dcf1b2360fff3cacbad081e0c733fc (patch) | |
tree | 1a62986d3b01e5521ecf3b913580af19d26fe1e8 /3party/Alohalytics | |
parent | 7845b9c6e31756d8a56bb3709186f691361903d6 (diff) |
[alohalytics] ATLOG can print log event time now.
Diffstat (limited to '3party/Alohalytics')
-rw-r--r-- | 3party/Alohalytics/src/logger.h | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/3party/Alohalytics/src/logger.h b/3party/Alohalytics/src/logger.h index b29b122f7b..e4135b14dc 100644 --- a/3party/Alohalytics/src/logger.h +++ b/3party/Alohalytics/src/logger.h @@ -25,6 +25,7 @@ #ifndef LOGGER_H #define LOGGER_H +#include <ctime> #include <sstream> #if defined(__OBJC__) @@ -46,19 +47,28 @@ namespace alohalytics { class Logger { std::ostringstream out_; + bool print_time_; public: - Logger() {} + Logger(bool print_time = true) : print_time_(print_time) {} Logger(const char * file, int line) { out_ << file << ':' << line << ": "; } ~Logger() { #if defined(__OBJC__) + // NSLog prints time automatically. NSLog(@"Alohalytics: %s", out_.str().c_str()); #elif defined(ANDROID) + // Android also prints time automatically. __android_log_print(ANDROID_LOG_INFO, "Alohalytics", "%s", out_.str().c_str()); #else - std::cout << "Alohalytics: " << out_.str() << std::endl; + if (print_time_) { + char buf[100] = ""; + const time_t now = time(nullptr); + (void)::strftime(buf, sizeof(buf), "%d/%b/%Y:%H:%M:%S ", ::localtime(&now)); + std::cout << buf; + } + std::cout << "Alohalytics: " << out_.str() << std::flush << std::endl; #endif } @@ -104,6 +114,7 @@ class Logger { } // namespace alohalytics #define ATRACE(...) alohalytics::Logger(__FILE__, __LINE__).Log(__VA_ARGS__) -#define ALOG(...) alohalytics::Logger().Log(__VA_ARGS__) +#define ALOG(...) alohalytics::Logger(false).Log(__VA_ARGS__) +#define ATLOG(...) alohalytics::Logger(true).Log(__VA_ARGS__) #endif |