Changeset 10989 for code/branches/cpp11_v2/src/libraries/util
- Timestamp:
- Dec 29, 2015, 11:35:49 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/src/libraries/util/output/LogWriter.cc
r9550 r10989 35 35 36 36 #include <ctime> 37 #include <chrono> 37 38 #include <cstdlib> 38 39 … … 180 181 return; 181 182 183 // get the milliseconds 184 std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); 185 std::chrono::system_clock::duration timeSinceEpoch = now.time_since_epoch(); 186 std::chrono::milliseconds millisSinceEpoch = std::chrono::duration_cast<std::chrono::milliseconds>(timeSinceEpoch); 187 unsigned int millis = (millisSinceEpoch.count() % 1000); 188 182 189 // get the current time 183 time_t rawtime; 184 struct tm* timeinfo; 185 time(&rawtime); 186 timeinfo = localtime(&rawtime); 190 time_t rawtime = std::chrono::system_clock::to_time_t(now); 191 struct tm* timeinfo = localtime(&rawtime); 192 193 // format time: hh:mm:ss:xxx 194 char buffer[13]; 195 snprintf(buffer, sizeof(buffer), "%.2i:%.2i:%.2i:%.3i", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, millis); 187 196 188 197 // print timestamp and output line to the log file 189 this->file_ << (timeinfo->tm_hour < 10 ? "0" : "") << timeinfo->tm_hour << ':' << 190 (timeinfo->tm_min < 10 ? "0" : "") << timeinfo->tm_min << ':' << 191 (timeinfo->tm_sec < 10 ? "0" : "") << timeinfo->tm_sec << ' ' << line << std::endl; 198 this->file_ << buffer << ' ' << line << std::endl; 192 199 } 193 200 }
Note: See TracChangeset
for help on using the changeset viewer.