----------------------------------------------------------------------------- Generate a string with formatted current time -----------------------------------------------------------------------------
| 257 | // Generate a string with formatted current time |
| 258 | //----------------------------------------------------------------------------- |
| 259 | string LogImpl::GetTimeStampString |
| 260 | ( |
| 261 | ) |
| 262 | { |
| 263 | // Get a timestamp |
| 264 | struct timeval tv; |
| 265 | gettimeofday(&tv, NULL); |
| 266 | // use threadsafe verion of localtime. Reported by nihilus, 2019-04 |
| 267 | // https://www.gnu.org/software/libc/manual/html_node/Broken_002ddown-Time.html#Broken_002ddown-Time |
| 268 | struct tm *tm, xtm; |
| 269 | memset(&xtm, 0, sizeof(xtm)); |
| 270 | tm = localtime_r( &tv.tv_sec, &xtm); |
| 271 | |
| 272 | // create a time stamp string for the log message |
| 273 | char buf[100]; |
| 274 | snprintf( buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d:%02d.%03d ", |
| 275 | tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, |
| 276 | tm->tm_hour, tm->tm_min, tm->tm_sec, (int)tv.tv_usec / 1000 ); |
| 277 | string str = buf; |
| 278 | return str; |
| 279 | } |
| 280 | |
| 281 | //----------------------------------------------------------------------------- |
| 282 | // <LogImpl::GetNodeString> |
nothing calls this directly
no test coverage detected