Skip to content

Commit cc40fb3

Browse files
committed
Deduping the emit functions, one now calls the other.
1 parent 0c2054b commit cc40fb3

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

lldb/tools/lldb-dap/DAPLog.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,18 @@ using namespace llvm;
1717

1818
namespace lldb_dap {
1919

20-
void Log::Emit(StringRef message) {
21-
std::lock_guard<Log::Mutex> lock(m_mutex);
22-
std::chrono::duration<double> now{
23-
std::chrono::system_clock::now().time_since_epoch()};
24-
m_stream << formatv("{0:f9} ", now.count()).str() << m_prefix << message
25-
<< "\n";
26-
m_stream.flush();
27-
}
20+
void Log::Emit(StringRef message) { Emit(message, "", 0); }
2821

29-
void Log::Emit(StringRef file, size_t line, StringRef message) {
22+
void Log::Emit(StringRef message, StringRef file, size_t line) {
3023
std::lock_guard<Log::Mutex> lock(m_mutex);
3124
std::chrono::duration<double> now{
3225
std::chrono::system_clock::now().time_since_epoch()};
33-
m_stream << formatv("{0:f9} {1}:{2} ", now.count(), sys::path::filename(file),
34-
line)
35-
.str()
36-
<< m_prefix << message << "\n";
26+
m_stream << formatv("{0:f9}", now.count()) << " ";
27+
if (!file.empty())
28+
m_stream << sys::path::filename(file) << ":" << line << " ";
29+
if (!m_prefix.empty())
30+
m_stream << m_prefix;
31+
m_stream << message << "\n";
3732
m_stream.flush();
3833
}
3934

lldb/tools/lldb-dap/DAPLog.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define DAP_LOG(log, ...) \
2121
do { \
2222
::lldb_dap::Log &log_private = (log); \
23-
log_private.Emit(__FILE__, __LINE__, ::llvm::formatv(__VA_ARGS__).str()); \
23+
log_private.Emit(::llvm::formatv(__VA_ARGS__).str(), __FILE__, __LINE__); \
2424
} while (0)
2525

2626
// Write message to log, if error is set. In the log message refer to the error
@@ -31,8 +31,8 @@
3131
::llvm::Error error_private = (error); \
3232
if (error_private) \
3333
log_private.Emit( \
34-
__FILE__, __LINE__, \
35-
::lldb_dap::FormatError(::std::move(error_private), __VA_ARGS__)); \
34+
::lldb_dap::FormatError(::std::move(error_private), __VA_ARGS__), \
35+
__FILE__, __LINE__); \
3636
} while (0)
3737

3838
namespace lldb_dap {
@@ -61,7 +61,7 @@ class Log final {
6161

6262
/// Emit writes a message to the underlying stream, including the file and
6363
/// line the message originated from.
64-
void Emit(llvm::StringRef file, size_t line, llvm::StringRef message);
64+
void Emit(llvm::StringRef message, llvm::StringRef file, size_t line);
6565

6666
private:
6767
std::string m_prefix;

lldb/unittests/DAP/DAPLogTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ TEST(DAPLog, Emit) {
3838
EXPECT_THAT(last_line(outs),
3939
MatchesRegex(TIMESTAMP_PATTERN "my_prefix: foobar\n"));
4040

41-
log.Emit("file.cpp", 42, "Hello from a file/line.");
41+
log.Emit("Hello from a file/line.", "file.cpp", 42);
4242
EXPECT_THAT(
4343
last_line(outs),
4444
MatchesRegex(TIMESTAMP_PATTERN "file.cpp:42 Hello from a file/line.\n"));
4545

46-
inner_log.Emit("file.cpp", 42, "Hello from a file/line.");
46+
inner_log.Emit("Hello from a file/line.", "file.cpp", 42);
4747
EXPECT_THAT(last_line(outs),
4848
MatchesRegex(TIMESTAMP_PATTERN
4949
"file.cpp:42 my_prefix: Hello from a file/line.\n"));

0 commit comments

Comments
 (0)