Swift: remove unneeded SwiftDiagnosticsDumper

This commit is contained in:
Paolo Tranquilli
2023-05-12 08:30:43 +02:00
parent 86777fa4c2
commit dedbd9ab63
3 changed files with 15 additions and 28 deletions

View File

@@ -66,31 +66,6 @@ struct SwiftDiagnostic {
}
};
class SwiftDiagnosticsDumper {
public:
// opens path for writing out JSON entries. Returns whether the operation was successful.
bool open(const std::filesystem::path& path) {
output.open(path);
return output.good();
}
void flush() { output.flush(); }
void write(const SwiftDiagnostic& source,
const std::chrono::system_clock::time_point& timestamp,
std::string_view message) {
if (output) {
output << source.json(timestamp, message) << '\n';
}
}
bool good() const { return output.good(); }
explicit operator bool() const { return good(); }
private:
std::ofstream output;
};
constexpr SwiftDiagnostic internalError{
"internal-error",
"Internal error",

View File

@@ -138,7 +138,8 @@ void Log::configure() {
std::error_code ec;
std::filesystem::create_directories(diagFile.parent_path(), ec);
if (!ec) {
if (!diagnostics.open(diagFile)) {
diagnostics.open(diagFile);
if (!diagnostics) {
problems.emplace_back("Unable to open diagnostics json file " + diagFile.string());
}
} else {
@@ -168,6 +169,14 @@ void Log::flushImpl() {
}
}
void Log::diagnoseImpl(const SwiftDiagnostic& source,
const std::chrono::system_clock::time_point& time,
std::string_view message) {
if (diagnostics) {
diagnostics << source.json(time, message) << '\n';
}
}
Log::LoggerConfiguration Log::getLoggerConfigurationImpl(std::string_view name) {
LoggerConfiguration ret{session, std::string{programName}};
ret.fullyQualifiedName += '/';

View File

@@ -126,7 +126,7 @@ class Log {
static void diagnose(const SwiftDiagnostic& source,
const std::chrono::system_clock::time_point& time,
std::string_view message) {
instance().diagnostics.write(source, time, message);
instance().diagnoseImpl(source, time, message);
}
private:
@@ -144,6 +144,9 @@ class Log {
void configure();
void flushImpl();
void diagnoseImpl(const SwiftDiagnostic& source,
const std::chrono::system_clock::time_point& time,
std::string_view message);
LoggerConfiguration getLoggerConfigurationImpl(std::string_view name);
@@ -183,7 +186,7 @@ class Log {
FilteredOutput<std::ofstream> binary{Level::no_logs};
FilteredOutput<binlog::TextOutputStream> text{Level::info, textFile, format};
FilteredOutput<binlog::TextOutputStream> console{Level::warning, std::cerr, format};
SwiftDiagnosticsDumper diagnostics{};
std::ofstream diagnostics{};
LevelRules sourceRules;
std::vector<std::string> collectLevelRulesAndReturnProblems(const char* envVar);
};