logger.hpp (27f6b686b385e5f946e5b3b2cf616bd7bb792bc4) | logger.hpp (fbf4703f3de7fbdbd8388e946bd71c3b760b174c) |
---|---|
1#pragma once 2 3#include "utility.hpp" 4 | 1#pragma once 2 3#include "utility.hpp" 4 |
5#include <fmt/format.h> | |
6#include <unistd.h> 7 8#include <nlohmann/json.hpp> 9#include <phosphor-logging/log.hpp> 10 11#include <cassert> 12#include <ctime> 13#include <filesystem> | 5#include <unistd.h> 6 7#include <nlohmann/json.hpp> 8#include <phosphor-logging/log.hpp> 9 10#include <cassert> 11#include <ctime> 12#include <filesystem> |
13#include <format> |
|
14#include <fstream> 15#include <iomanip> 16#include <sstream> 17#include <string> 18#include <vector> 19 20namespace phosphor::fan 21{ --- 110 unchanged lines hidden (view full) --- 132 { 133 throw std::runtime_error{"mkstemp failed!"}; 134 } 135 136 std::filesystem::path path{tmpFile}; 137 138 for (const auto& [time, message] : _entries) 139 { | 14#include <fstream> 15#include <iomanip> 16#include <sstream> 17#include <string> 18#include <vector> 19 20namespace phosphor::fan 21{ --- 110 unchanged lines hidden (view full) --- 132 { 133 throw std::runtime_error{"mkstemp failed!"}; 134 } 135 136 std::filesystem::path path{tmpFile}; 137 138 for (const auto& [time, message] : _entries) 139 { |
140 auto line = fmt::format("{}: {}\n", time, message); | 140 auto line = std::format("{}: {}\n", time, message); |
141 auto rc = write(fd(), line.data(), line.size()); 142 if (rc == -1) 143 { 144 auto e = errno; | 141 auto rc = write(fd(), line.data(), line.size()); 142 if (rc == -1) 143 { 144 auto e = errno; |
145 auto msg = fmt::format( | 145 auto msg = std::format( |
146 "Could not write to temp file {} errno {}", tmpFile, e); 147 log(msg, Logger::error); 148 throw std::runtime_error{msg}; 149 } 150 } 151 152 return std::filesystem::path{tmpFile}; 153 } --- 22 unchanged lines hidden --- | 146 "Could not write to temp file {} errno {}", tmpFile, e); 147 log(msg, Logger::error); 148 throw std::runtime_error{msg}; 149 } 150 } 151 152 return std::filesystem::path{tmpFile}; 153 } --- 22 unchanged lines hidden --- |