7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " LogChannelSwift.h"
10
+ #include " lldb/Utility/Log.h"
10
11
#include " lldb/Version/Version.h"
11
12
12
13
using namespace lldb_private ;
@@ -25,20 +26,39 @@ template <> Log::Channel &lldb_private::LogChannelFor<SwiftLog>() {
25
26
return g_channel;
26
27
}
27
28
29
+ class StringLogHandler : public LogHandler {
30
+ public:
31
+ StringLogHandler (std::string& str) : m_string(str) {}
32
+
33
+ void Emit (llvm::StringRef message) override {
34
+ std::lock_guard<std::mutex> guard (m_mutex);
35
+ m_string += std::string (message);
36
+ }
37
+
38
+ bool isA (const void *ClassID) const override { return ClassID == &ID; }
39
+ static bool classof (const LogHandler *obj) { return obj->isA (&ID); }
40
+
41
+ private:
42
+ std::mutex m_mutex;
43
+ std::string& m_string;
44
+ static char ID;
45
+ };
46
+
47
+ char StringLogHandler::ID;
48
+
28
49
void LogChannelSwift::Initialize () {
29
50
Log::Register (" swift" , g_channel);
30
51
31
- llvm::raw_null_ostream error_stream;
32
- Log::EnableLogChannel (
33
- std::make_shared<llvm::raw_string_ostream>(g_swift_log_buffer),
34
- LLDB_LOG_OPTION_THREADSAFE, " swift" , {" health" }, error_stream);
52
+ auto log_handler_sp = std::make_shared<StringLogHandler>(g_swift_log_buffer);
53
+ Log::EnableLogChannel (log_handler_sp, 0 , " swift" , {" health" }, llvm::nulls ());
35
54
if (Log *log = GetSwiftHealthLog ())
36
55
log->Printf (
37
56
" ==== LLDB swift-healthcheck log. ===\n "
38
57
" This file contains the configuration of LLDB's embedded Swift "
39
58
" compiler to help diagnosing module import and search path issues. "
40
59
" The swift-healthcheck command is meant to be run *after* an error "
41
- " has occurred.\n %s" , lldb_private::GetVersion ());
60
+ " has occurred.\n %s" ,
61
+ lldb_private::GetVersion ());
42
62
}
43
63
44
64
void LogChannelSwift::Terminate () { Log::Unregister (" swift" ); }
0 commit comments