Changeset 10989
- Timestamp:
- Dec 29, 2015, 11:35:49 AM (9 years ago)
- Location:
- code/branches/cpp11_v2
- Files:
-
- 2 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 } -
code/branches/cpp11_v2/test/util/output/LogWriterTest.cc
r10846 r10989 137 137 std::string line = getLineWhichContains(path, "myothertestoutput"); 138 138 EXPECT_FALSE(line.empty()); 139 ASSERT_TRUE(line.length() > 12); 140 139 141 EXPECT_TRUE(isdigit(line[0])); 140 142 EXPECT_TRUE(isdigit(line[1])); … … 145 147 EXPECT_TRUE(isdigit(line[6])); 146 148 EXPECT_TRUE(isdigit(line[7])); 147 EXPECT_EQ(' ', line[8]); 149 EXPECT_EQ(':', line[8]); 150 EXPECT_TRUE(isdigit(line[9])); 151 EXPECT_TRUE(isdigit(line[10])); 152 EXPECT_TRUE(isdigit(line[11])); 153 EXPECT_EQ(' ', line[12]); 148 154 } 149 155
Note: See TracChangeset
for help on using the changeset viewer.