Skip to content

Commit dedbd9a

Browse files
committed
Swift: remove unneeded SwiftDiagnosticsDumper
1 parent 86777fa commit dedbd9a

File tree

3 files changed

+15
-28
lines changed

3 files changed

+15
-28
lines changed

swift/logging/SwiftDiagnostics.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,6 @@ struct SwiftDiagnostic {
6666
}
6767
};
6868

69-
class SwiftDiagnosticsDumper {
70-
public:
71-
// opens path for writing out JSON entries. Returns whether the operation was successful.
72-
bool open(const std::filesystem::path& path) {
73-
output.open(path);
74-
return output.good();
75-
}
76-
77-
void flush() { output.flush(); }
78-
79-
void write(const SwiftDiagnostic& source,
80-
const std::chrono::system_clock::time_point& timestamp,
81-
std::string_view message) {
82-
if (output) {
83-
output << source.json(timestamp, message) << '\n';
84-
}
85-
}
86-
87-
bool good() const { return output.good(); }
88-
explicit operator bool() const { return good(); }
89-
90-
private:
91-
std::ofstream output;
92-
};
93-
9469
constexpr SwiftDiagnostic internalError{
9570
"internal-error",
9671
"Internal error",

swift/logging/SwiftLogging.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ void Log::configure() {
138138
std::error_code ec;
139139
std::filesystem::create_directories(diagFile.parent_path(), ec);
140140
if (!ec) {
141-
if (!diagnostics.open(diagFile)) {
141+
diagnostics.open(diagFile);
142+
if (!diagnostics) {
142143
problems.emplace_back("Unable to open diagnostics json file " + diagFile.string());
143144
}
144145
} else {
@@ -168,6 +169,14 @@ void Log::flushImpl() {
168169
}
169170
}
170171

172+
void Log::diagnoseImpl(const SwiftDiagnostic& source,
173+
const std::chrono::system_clock::time_point& time,
174+
std::string_view message) {
175+
if (diagnostics) {
176+
diagnostics << source.json(time, message) << '\n';
177+
}
178+
}
179+
171180
Log::LoggerConfiguration Log::getLoggerConfigurationImpl(std::string_view name) {
172181
LoggerConfiguration ret{session, std::string{programName}};
173182
ret.fullyQualifiedName += '/';

swift/logging/SwiftLogging.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class Log {
126126
static void diagnose(const SwiftDiagnostic& source,
127127
const std::chrono::system_clock::time_point& time,
128128
std::string_view message) {
129-
instance().diagnostics.write(source, time, message);
129+
instance().diagnoseImpl(source, time, message);
130130
}
131131

132132
private:
@@ -144,6 +144,9 @@ class Log {
144144

145145
void configure();
146146
void flushImpl();
147+
void diagnoseImpl(const SwiftDiagnostic& source,
148+
const std::chrono::system_clock::time_point& time,
149+
std::string_view message);
147150

148151
LoggerConfiguration getLoggerConfigurationImpl(std::string_view name);
149152

@@ -183,7 +186,7 @@ class Log {
183186
FilteredOutput<std::ofstream> binary{Level::no_logs};
184187
FilteredOutput<binlog::TextOutputStream> text{Level::info, textFile, format};
185188
FilteredOutput<binlog::TextOutputStream> console{Level::warning, std::cerr, format};
186-
SwiftDiagnosticsDumper diagnostics{};
189+
std::ofstream diagnostics{};
187190
LevelRules sourceRules;
188191
std::vector<std::string> collectLevelRulesAndReturnProblems(const char* envVar);
189192
};

0 commit comments

Comments
 (0)