Skip to content

Commit f43227e

Browse files
committed
Simplify log messages
1 parent e47d033 commit f43227e

File tree

1 file changed

+1
-54
lines changed

1 file changed

+1
-54
lines changed

utils/log.hpp

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#include <cstdio>
4646

4747

48-
inline std::string NowTime();
49-
5048
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG,
5149
logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4};
5250

@@ -76,8 +74,7 @@ Log<T>::Log()
7674
template <typename T>
7775
std::ostringstream& Log<T>::Get(TLogLevel level)
7876
{
79-
os << "- " << NowTime();
80-
os << " " << ToString(level) << ": ";
77+
os << "- " << ToString(level) << ": ";
8178
os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t');
8279
return os;
8380
}
@@ -172,54 +169,4 @@ class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
172169
else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \
173170
else FILELog().Get(level)
174171

175-
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
176-
177-
#ifndef NOMINMAX
178-
# define NOMINMAX
179-
#endif
180-
#include <windows.h>
181-
182-
inline std::string NowTime()
183-
{
184-
const int MAX_LEN = 200;
185-
char buffer[MAX_LEN];
186-
if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0,
187-
"HH':'mm':'ss", buffer, MAX_LEN) == 0)
188-
return "Error in NowTime()";
189-
190-
char result[100] = {0};
191-
static DWORD first = GetTickCount();
192-
std::sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000);
193-
return result;
194-
}
195-
196-
#else
197-
198-
#include <sys/time.h>
199-
200-
inline std::string NowTime()
201-
{
202-
struct timeval tv;
203-
gettimeofday(&tv, 0);
204-
char buffer[11];
205-
tm r = {0};
206-
strftime(buffer, sizeof(buffer), "%X", localtime_r(&tv.tv_sec, &r));
207-
char result[100] = {0};
208-
std::sprintf(result, "%s.%06ld", buffer, (long)tv.tv_usec);
209-
return result;
210-
211-
// char buffer[11];
212-
// time_t t;
213-
// time(&t);
214-
// tm r = {0};
215-
// strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r));
216-
// struct timeval tv;
217-
// gettimeofday(&tv, 0);
218-
// char result[100] = {0};
219-
// std::sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000);
220-
// return result;
221-
}
222-
223-
#endif //WIN32
224-
225172
#endif //__LOG_H__

0 commit comments

Comments
 (0)