| 424 | } |
| 425 | |
| 426 | void Log2File(const std::string& log) { |
| 427 | // We can have multiple threads and/or processes, so try to prevent them |
| 428 | // from clobbering each other's writes. |
| 429 | // If the client app did not call InitLogging, and the lock has not |
| 430 | // been created do it now. We do this on demand, but if two threads try |
| 431 | // to do this at the same time, there will be a race condition to create |
| 432 | // the lock. This is why InitLogging should be called from the main |
| 433 | // thread at the beginning of execution. |
| 434 | LoggingLock::Init(LOCK_LOG_FILE, NULL); |
| 435 | LoggingLock logging_lock; |
| 436 | if (InitializeLogFileHandle()) { |
| 437 | #if defined(OS_WIN) |
| 438 | SetFilePointer(log_file, 0, 0, SEEK_END); |
| 439 | DWORD num_written; |
| 440 | WriteFile(log_file, static_cast<const void*>(log.data()), |
| 441 | static_cast<DWORD>(log.size()), &num_written, NULL); |
| 442 | #else |
| 443 | fwrite(log.data(), log.size(), 1, log_file); |
| 444 | fflush(log_file); |
| 445 | #endif |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | } // namespace |
| 450 |
no test coverage detected