base: remove LOG_TO(), PLOG_TO() and LOG_STREAM_TO() macros
There were only two users of these and both of them were better off
setting up a default logger.
These macros are not particularly useful as it's not useful for a
single program to write to both the MAIN and SYSTEM logs. In fact,
the opposite of these macros would be more beneficial: having more
programs write to only the MAIN or only the SYSTEM buffer, so getting
rid of these macros removes a temptation for bad behavior.
Users that absolutely need to do this behavior can still use the
liblog macros or functions, but that should be an extreme edge case,
such as the few programs that write to the CRASH buffer and does not
need to exist in libbase.
Bug: 119867234
Test: build
Change-Id: I23369c3b48ed636b617220cab47f77fdd5559763
diff --git a/base/logging.cpp b/base/logging.cpp
index f89168c..598a522 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -350,11 +350,10 @@
// checks/logging in a function.
class LogMessageData {
public:
- LogMessageData(const char* file, unsigned int line, LogId id, LogSeverity severity,
- const char* tag, int error)
+ LogMessageData(const char* file, unsigned int line, LogSeverity severity, const char* tag,
+ int error)
: file_(GetFileBasename(file)),
line_number_(line),
- id_(id),
severity_(severity),
tag_(tag),
error_(error) {}
@@ -373,10 +372,6 @@
const char* GetTag() const { return tag_; }
- LogId GetId() const {
- return id_;
- }
-
int GetError() const {
return error_;
}
@@ -393,7 +388,6 @@
std::ostringstream buffer_;
const char* const file_;
const unsigned int line_number_;
- const LogId id_;
const LogSeverity severity_;
const char* const tag_;
const int error_;
@@ -401,9 +395,13 @@
DISALLOW_COPY_AND_ASSIGN(LogMessageData);
};
-LogMessage::LogMessage(const char* file, unsigned int line, LogId id, LogSeverity severity,
+LogMessage::LogMessage(const char* file, unsigned int line, LogId, LogSeverity severity,
const char* tag, int error)
- : data_(new LogMessageData(file, line, id, severity, tag, error)) {}
+ : LogMessage(file, line, severity, tag, error) {}
+
+LogMessage::LogMessage(const char* file, unsigned int line, LogSeverity severity, const char* tag,
+ int error)
+ : data_(new LogMessageData(file, line, severity, tag, error)) {}
LogMessage::~LogMessage() {
// Check severity again. This is duplicate work wrt/ LOG macros, but not LOG_STREAM.
@@ -429,16 +427,16 @@
// Do the actual logging with the lock held.
std::lock_guard<std::mutex> lock(LoggingLock());
if (msg.find('\n') == std::string::npos) {
- LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(), data_->GetSeverity(),
- data_->GetTag(), msg.c_str());
+ LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetSeverity(), data_->GetTag(),
+ msg.c_str());
} else {
msg += '\n';
size_t i = 0;
while (i < msg.size()) {
size_t nl = msg.find('\n', i);
msg[nl] = '\0';
- LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(), data_->GetSeverity(),
- data_->GetTag(), &msg[i]);
+ LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetSeverity(), data_->GetTag(),
+ &msg[i]);
// Undo the zero-termination so we can give the complete message to the aborter.
msg[nl] = '\n';
i = nl + 1;
@@ -456,16 +454,16 @@
return data_->GetBuffer();
}
-void LogMessage::LogLine(const char* file, unsigned int line, LogId id, LogSeverity severity,
- const char* tag, const char* message) {
+void LogMessage::LogLine(const char* file, unsigned int line, LogSeverity severity, const char* tag,
+ const char* message) {
if (tag == nullptr) {
std::lock_guard<std::recursive_mutex> lock(TagLock());
if (gDefaultTag == nullptr) {
gDefaultTag = new std::string(getprogname());
}
- Logger()(id, severity, gDefaultTag->c_str(), file, line, message);
+ Logger()(DEFAULT, severity, gDefaultTag->c_str(), file, line, message);
} else {
- Logger()(id, severity, tag, file, line, message);
+ Logger()(DEFAULT, severity, tag, file, line, message);
}
}