| 224 | } |
| 225 | |
| 226 | void LogFile::InitLogFile(const std::string &base_name) { |
| 227 | try { |
| 228 | stop_thread_ = true; |
| 229 | if (worker_thread_.joinable()) { |
| 230 | condition_.notify_one(); |
| 231 | worker_thread_.join(); |
| 232 | } |
| 233 | stop_thread_ = false; |
| 234 | if (file_ != nullptr) { |
| 235 | fclose(file_); |
| 236 | file_ = nullptr; |
| 237 | } |
| 238 | filename_ = {}; |
| 239 | path p = FindLogPath(base_name); |
| 240 | if (p.empty()) { |
| 241 | throw std::ios_base::failure(std::string("Path is empty. Path: ") + |
| 242 | p.string()); |
| 243 | } |
| 244 | if (!exists(p.parent_path())) { |
| 245 | throw std::ios_base::failure(std::string("Path does not exist Path: ") + |
| 246 | p.string()); |
| 247 | } |
| 248 | filename_ = p.string(); |
| 249 | StartWorkerThread(); |
| 250 | } catch (const std::exception &error) { |
| 251 | std::cerr << "Couldn't initiate a log file. Error: " << error.what() |
| 252 | << std::endl; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | bool LogFile::HasLogFile() const { return !filename_.empty(); } |
| 257 |
nothing calls this directly
no test coverage detected