blob: a31feefab2f519847e6803313e64f85666f26cda [file] [log] [blame]
Dan Albert58310b42015-03-13 23:06:01 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Elliott Hughes7bc87a52016-08-04 16:09:39 -070017#if defined(_WIN32)
Spencer Lowac3f7d92015-05-19 22:12:06 -070018#include <windows.h>
19#endif
20
Elliott Hughes4f713192015-12-04 22:00:26 -080021#include "android-base/logging.h"
Dan Albert58310b42015-03-13 23:06:01 -070022
Elliott Hughes7bc87a52016-08-04 16:09:39 -070023#include <fcntl.h>
Dan Albert7a87d052015-04-03 11:28:46 -070024#include <libgen.h>
Elliott Hughes4e5fd112016-06-21 14:25:44 -070025#include <time.h>
Dan Albert7a87d052015-04-03 11:28:46 -070026
27// For getprogname(3) or program_invocation_short_name.
28#if defined(__ANDROID__) || defined(__APPLE__)
29#include <stdlib.h>
30#elif defined(__GLIBC__)
31#include <errno.h>
32#endif
33
Elliott Hughes7bc87a52016-08-04 16:09:39 -070034#if defined(__linux__)
35#include <sys/uio.h>
36#endif
37
Dan Albert58310b42015-03-13 23:06:01 -070038#include <iostream>
39#include <limits>
Josh Gao63bdcb52016-09-13 14:57:12 -070040#include <mutex>
Dan Albert58310b42015-03-13 23:06:01 -070041#include <sstream>
42#include <string>
Dan Albertb547c852015-03-27 11:20:14 -070043#include <utility>
Dan Albert58310b42015-03-13 23:06:01 -070044#include <vector>
45
Dan Albert58310b42015-03-13 23:06:01 -070046// Headers for LogMessage::LogLine.
47#ifdef __ANDROID__
Andreas Gampeaf05f3b2018-02-15 11:40:30 -080048#include <android/log.h>
Dan Albert58310b42015-03-13 23:06:01 -070049#include <android/set_abort_message.h>
Dan Albert58310b42015-03-13 23:06:01 -070050#else
51#include <sys/types.h>
52#include <unistd.h>
53#endif
54
Mark Salyzynff2dcd92016-09-28 15:54:45 -070055#include <android-base/macros.h>
56#include <android-base/strings.h>
57
Elliott Hughesc1fd4922015-11-11 18:02:29 +000058// For gettid.
59#if defined(__APPLE__)
60#include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED
61#include <stdint.h>
62#include <stdlib.h>
63#include <sys/syscall.h>
64#include <sys/time.h>
65#include <unistd.h>
66#elif defined(__linux__) && !defined(__ANDROID__)
67#include <syscall.h>
68#include <unistd.h>
69#elif defined(_WIN32)
70#include <windows.h>
71#endif
72
Dan Willemsen86cf9412016-02-03 23:29:32 -080073#if defined(_WIN32)
74typedef uint32_t thread_id;
75#else
76typedef pid_t thread_id;
77#endif
78
79static thread_id GetThreadId() {
Elliott Hughesc1fd4922015-11-11 18:02:29 +000080#if defined(__BIONIC__)
81 return gettid();
82#elif defined(__APPLE__)
Christopher N. Hesse684b4422016-09-17 18:29:03 +020083 uint64_t tid;
84 pthread_threadid_np(NULL, &tid);
85 return tid;
Elliott Hughesc1fd4922015-11-11 18:02:29 +000086#elif defined(__linux__)
87 return syscall(__NR_gettid);
88#elif defined(_WIN32)
89 return GetCurrentThreadId();
90#endif
91}
92
Dan Albert5c190402015-04-29 11:32:23 -070093namespace {
Dan Albert5c190402015-04-29 11:32:23 -070094#if defined(__GLIBC__)
95const char* getprogname() {
96 return program_invocation_short_name;
97}
Josh Gao63bdcb52016-09-13 14:57:12 -070098#elif defined(_WIN32)
Dan Albert5c190402015-04-29 11:32:23 -070099const char* getprogname() {
100 static bool first = true;
101 static char progname[MAX_PATH] = {};
102
103 if (first) {
Spencer Lowbdab59a2015-08-11 16:00:13 -0700104 CHAR longname[MAX_PATH];
105 DWORD nchars = GetModuleFileNameA(nullptr, longname, arraysize(longname));
106 if ((nchars >= arraysize(longname)) || (nchars == 0)) {
107 // String truncation or some other error.
108 strcpy(progname, "<unknown>");
109 } else {
110 strcpy(progname, basename(longname));
111 }
Dan Albert5c190402015-04-29 11:32:23 -0700112 first = false;
113 }
114
115 return progname;
116}
Dan Albert5c190402015-04-29 11:32:23 -0700117#endif
118} // namespace
119
Dan Albert58310b42015-03-13 23:06:01 -0700120namespace android {
121namespace base {
122
Yabin Cui0c689532017-01-23 10:29:23 -0800123static std::mutex& LoggingLock() {
124 static auto& logging_lock = *new std::mutex();
125 return logging_lock;
126}
Dan Albert58310b42015-03-13 23:06:01 -0700127
Yabin Cui0c689532017-01-23 10:29:23 -0800128static LogFunction& Logger() {
Dan Albertb547c852015-03-27 11:20:14 -0700129#ifdef __ANDROID__
Yabin Cui0c689532017-01-23 10:29:23 -0800130 static auto& logger = *new LogFunction(LogdLogger());
Dan Albertb547c852015-03-27 11:20:14 -0700131#else
Yabin Cui0c689532017-01-23 10:29:23 -0800132 static auto& logger = *new LogFunction(StderrLogger);
Dan Albertb547c852015-03-27 11:20:14 -0700133#endif
Yabin Cui0c689532017-01-23 10:29:23 -0800134 return logger;
135}
Dan Albertb547c852015-03-27 11:20:14 -0700136
Yabin Cui0c689532017-01-23 10:29:23 -0800137static AbortFunction& Aborter() {
138 static auto& aborter = *new AbortFunction(DefaultAborter);
139 return aborter;
140}
141
Andreas Gampe3aa89362018-03-05 10:00:19 -0800142static std::recursive_mutex& TagLock() {
143 static auto& tag_lock = *new std::recursive_mutex();
144 return tag_lock;
145}
146static std::string* gDefaultTag;
147std::string GetDefaultTag() {
148 std::lock_guard<std::recursive_mutex> lock(TagLock());
149 if (gDefaultTag == nullptr) {
150 return "";
151 }
152 return *gDefaultTag;
153}
154void SetDefaultTag(const std::string& tag) {
155 std::lock_guard<std::recursive_mutex> lock(TagLock());
156 if (gDefaultTag != nullptr) {
157 delete gDefaultTag;
158 gDefaultTag = nullptr;
159 }
160 if (!tag.empty()) {
161 gDefaultTag = new std::string(tag);
162 }
Yabin Cui0c689532017-01-23 10:29:23 -0800163}
Andreas Gampe2691e332016-09-08 11:03:58 -0700164
Dan Albert7a87d052015-04-03 11:28:46 -0700165static bool gInitialized = false;
Dan Albert58310b42015-03-13 23:06:01 -0700166static LogSeverity gMinimumLogSeverity = INFO;
Dan Albert58310b42015-03-13 23:06:01 -0700167
Elliott Hughes7bc87a52016-08-04 16:09:39 -0700168#if defined(__linux__)
169void KernelLogger(android::base::LogId, android::base::LogSeverity severity,
170 const char* tag, const char*, unsigned int, const char* msg) {
Andreas Gampe550829d2016-09-07 10:10:50 -0700171 // clang-format off
Elliott Hughes7bc87a52016-08-04 16:09:39 -0700172 static constexpr int kLogSeverityToKernelLogLevel[] = {
Andreas Gampe550829d2016-09-07 10:10:50 -0700173 [android::base::VERBOSE] = 7, // KERN_DEBUG (there is no verbose kernel log
174 // level)
175 [android::base::DEBUG] = 7, // KERN_DEBUG
176 [android::base::INFO] = 6, // KERN_INFO
177 [android::base::WARNING] = 4, // KERN_WARNING
178 [android::base::ERROR] = 3, // KERN_ERROR
179 [android::base::FATAL_WITHOUT_ABORT] = 2, // KERN_CRIT
180 [android::base::FATAL] = 2, // KERN_CRIT
Elliott Hughes7bc87a52016-08-04 16:09:39 -0700181 };
Andreas Gampe550829d2016-09-07 10:10:50 -0700182 // clang-format on
Elliott Hughes7bc87a52016-08-04 16:09:39 -0700183 static_assert(arraysize(kLogSeverityToKernelLogLevel) == android::base::FATAL + 1,
184 "Mismatch in size of kLogSeverityToKernelLogLevel and values in LogSeverity");
185
186 static int klog_fd = TEMP_FAILURE_RETRY(open("/dev/kmsg", O_WRONLY | O_CLOEXEC));
187 if (klog_fd == -1) return;
188
189 int level = kLogSeverityToKernelLogLevel[severity];
190
191 // The kernel's printk buffer is only 1024 bytes.
192 // TODO: should we automatically break up long lines into multiple lines?
193 // Or we could log but with something like "..." at the end?
194 char buf[1024];
195 size_t size = snprintf(buf, sizeof(buf), "<%d>%s: %s\n", level, tag, msg);
196 if (size > sizeof(buf)) {
197 size = snprintf(buf, sizeof(buf), "<%d>%s: %zu-byte message too long for printk\n",
198 level, tag, size);
199 }
200
201 iovec iov[1];
202 iov[0].iov_base = buf;
203 iov[0].iov_len = size;
204 TEMP_FAILURE_RETRY(writev(klog_fd, iov, 1));
205}
206#endif
207
Tomasz Wasilczykc2516002017-12-18 06:30:17 -0800208void StderrLogger(LogId, LogSeverity severity, const char* tag, const char* file, unsigned int line,
209 const char* message) {
Elliott Hughes4e5fd112016-06-21 14:25:44 -0700210 struct tm now;
211 time_t t = time(nullptr);
212
213#if defined(_WIN32)
214 localtime_s(&now, &t);
215#else
216 localtime_r(&t, &now);
217#endif
218
219 char timestamp[32];
220 strftime(timestamp, sizeof(timestamp), "%m-%d %H:%M:%S", &now);
221
Andreas Gampe550829d2016-09-07 10:10:50 -0700222 static const char log_characters[] = "VDIWEFF";
Spencer Lowbdab59a2015-08-11 16:00:13 -0700223 static_assert(arraysize(log_characters) - 1 == FATAL + 1,
224 "Mismatch in size of log_characters and values in LogSeverity");
Dan Albertb547c852015-03-27 11:20:14 -0700225 char severity_char = log_characters[severity];
Tomasz Wasilczykc2516002017-12-18 06:30:17 -0800226 fprintf(stderr, "%s %c %s %5d %5d %s:%u] %s\n", tag ? tag : "nullptr", severity_char, timestamp,
227 getpid(), GetThreadId(), file, line, message);
Dan Albertb547c852015-03-27 11:20:14 -0700228}
229
Andreas Gampe2691e332016-09-08 11:03:58 -0700230void DefaultAborter(const char* abort_message) {
231#ifdef __ANDROID__
232 android_set_abort_message(abort_message);
233#else
234 UNUSED(abort_message);
235#endif
236 abort();
237}
238
Dan Albertb547c852015-03-27 11:20:14 -0700239
240#ifdef __ANDROID__
241LogdLogger::LogdLogger(LogId default_log_id) : default_log_id_(default_log_id) {
242}
243
Dan Albertb547c852015-03-27 11:20:14 -0700244void LogdLogger::operator()(LogId id, LogSeverity severity, const char* tag,
245 const char* file, unsigned int line,
246 const char* message) {
Elliott Hughes7bc87a52016-08-04 16:09:39 -0700247 static constexpr android_LogPriority kLogSeverityToAndroidLogPriority[] = {
Andreas Gampe550829d2016-09-07 10:10:50 -0700248 ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO,
249 ANDROID_LOG_WARN, ANDROID_LOG_ERROR, ANDROID_LOG_FATAL,
250 ANDROID_LOG_FATAL,
Elliott Hughes7bc87a52016-08-04 16:09:39 -0700251 };
252 static_assert(arraysize(kLogSeverityToAndroidLogPriority) == FATAL + 1,
253 "Mismatch in size of kLogSeverityToAndroidLogPriority and values in LogSeverity");
254
Dan Albertb547c852015-03-27 11:20:14 -0700255 int priority = kLogSeverityToAndroidLogPriority[severity];
256 if (id == DEFAULT) {
257 id = default_log_id_;
258 }
259
Elliott Hughes7bc87a52016-08-04 16:09:39 -0700260 static constexpr log_id kLogIdToAndroidLogId[] = {
261 LOG_ID_MAX, LOG_ID_MAIN, LOG_ID_SYSTEM,
262 };
263 static_assert(arraysize(kLogIdToAndroidLogId) == SYSTEM + 1,
264 "Mismatch in size of kLogIdToAndroidLogId and values in LogId");
Dan Albertb547c852015-03-27 11:20:14 -0700265 log_id lg_id = kLogIdToAndroidLogId[id];
266
267 if (priority == ANDROID_LOG_FATAL) {
268 __android_log_buf_print(lg_id, priority, tag, "%s:%u] %s", file, line,
269 message);
270 } else {
271 __android_log_buf_print(lg_id, priority, tag, "%s", message);
272 }
273}
274#endif
275
Andreas Gampe2691e332016-09-08 11:03:58 -0700276void InitLogging(char* argv[], LogFunction&& logger, AbortFunction&& aborter) {
Dan Albertb547c852015-03-27 11:20:14 -0700277 SetLogger(std::forward<LogFunction>(logger));
Andreas Gampe2691e332016-09-08 11:03:58 -0700278 SetAborter(std::forward<AbortFunction>(aborter));
Dan Albertb547c852015-03-27 11:20:14 -0700279
Dan Albert7a87d052015-04-03 11:28:46 -0700280 if (gInitialized) {
Dan Albert58310b42015-03-13 23:06:01 -0700281 return;
282 }
283
Dan Albert7a87d052015-04-03 11:28:46 -0700284 gInitialized = true;
285
Dan Albert58310b42015-03-13 23:06:01 -0700286 // Stash the command line for later use. We can use /proc/self/cmdline on
Spencer Low363af562015-11-07 18:51:54 -0800287 // Linux to recover this, but we don't have that luxury on the Mac/Windows,
288 // and there are a couple of argv[0] variants that are commonly used.
Dan Albert58310b42015-03-13 23:06:01 -0700289 if (argv != nullptr) {
Andreas Gampe3aa89362018-03-05 10:00:19 -0800290 SetDefaultTag(basename(argv[0]));
Dan Albert58310b42015-03-13 23:06:01 -0700291 }
Dan Albert7a87d052015-04-03 11:28:46 -0700292
Dan Albert58310b42015-03-13 23:06:01 -0700293 const char* tags = getenv("ANDROID_LOG_TAGS");
294 if (tags == nullptr) {
295 return;
296 }
297
Dan Albert47328c92015-03-19 13:24:26 -0700298 std::vector<std::string> specs = Split(tags, " ");
Dan Albert58310b42015-03-13 23:06:01 -0700299 for (size_t i = 0; i < specs.size(); ++i) {
300 // "tag-pattern:[vdiwefs]"
301 std::string spec(specs[i]);
302 if (spec.size() == 3 && StartsWith(spec, "*:")) {
303 switch (spec[2]) {
304 case 'v':
305 gMinimumLogSeverity = VERBOSE;
306 continue;
307 case 'd':
308 gMinimumLogSeverity = DEBUG;
309 continue;
310 case 'i':
311 gMinimumLogSeverity = INFO;
312 continue;
313 case 'w':
314 gMinimumLogSeverity = WARNING;
315 continue;
316 case 'e':
317 gMinimumLogSeverity = ERROR;
318 continue;
319 case 'f':
Andreas Gampe550829d2016-09-07 10:10:50 -0700320 gMinimumLogSeverity = FATAL_WITHOUT_ABORT;
Dan Albert58310b42015-03-13 23:06:01 -0700321 continue;
322 // liblog will even suppress FATAL if you say 's' for silent, but that's
323 // crazy!
324 case 's':
Andreas Gampe550829d2016-09-07 10:10:50 -0700325 gMinimumLogSeverity = FATAL_WITHOUT_ABORT;
Dan Albert58310b42015-03-13 23:06:01 -0700326 continue;
327 }
328 }
329 LOG(FATAL) << "unsupported '" << spec << "' in ANDROID_LOG_TAGS (" << tags
330 << ")";
331 }
332}
333
Dan Albertb547c852015-03-27 11:20:14 -0700334void SetLogger(LogFunction&& logger) {
Yabin Cui0c689532017-01-23 10:29:23 -0800335 std::lock_guard<std::mutex> lock(LoggingLock());
336 Logger() = std::move(logger);
Dan Albertb547c852015-03-27 11:20:14 -0700337}
338
Andreas Gampe2691e332016-09-08 11:03:58 -0700339void SetAborter(AbortFunction&& aborter) {
Yabin Cui0c689532017-01-23 10:29:23 -0800340 std::lock_guard<std::mutex> lock(LoggingLock());
341 Aborter() = std::move(aborter);
Andreas Gampe2691e332016-09-08 11:03:58 -0700342}
343
Spencer Lowbdab59a2015-08-11 16:00:13 -0700344static const char* GetFileBasename(const char* file) {
Spencer Low363af562015-11-07 18:51:54 -0800345 // We can't use basename(3) even on Unix because the Mac doesn't
346 // have a non-modifying basename.
Spencer Lowbdab59a2015-08-11 16:00:13 -0700347 const char* last_slash = strrchr(file, '/');
Spencer Low363af562015-11-07 18:51:54 -0800348 if (last_slash != nullptr) {
349 return last_slash + 1;
350 }
351#if defined(_WIN32)
352 const char* last_backslash = strrchr(file, '\\');
353 if (last_backslash != nullptr) {
354 return last_backslash + 1;
355 }
356#endif
357 return file;
Spencer Lowbdab59a2015-08-11 16:00:13 -0700358}
359
Dan Albert58310b42015-03-13 23:06:01 -0700360// This indirection greatly reduces the stack impact of having lots of
361// checks/logging in a function.
362class LogMessageData {
363 public:
Tomasz Wasilczykc2516002017-12-18 06:30:17 -0800364 LogMessageData(const char* file, unsigned int line, LogId id, LogSeverity severity,
365 const char* tag, int error)
Spencer Lowbdab59a2015-08-11 16:00:13 -0700366 : file_(GetFileBasename(file)),
Dan Albert0c055862015-03-27 11:20:14 -0700367 line_number_(line),
368 id_(id),
369 severity_(severity),
Tomasz Wasilczykc2516002017-12-18 06:30:17 -0800370 tag_(tag),
371 error_(error) {}
Dan Albert58310b42015-03-13 23:06:01 -0700372
373 const char* GetFile() const {
374 return file_;
375 }
376
377 unsigned int GetLineNumber() const {
378 return line_number_;
379 }
380
381 LogSeverity GetSeverity() const {
382 return severity_;
383 }
384
Tomasz Wasilczykc2516002017-12-18 06:30:17 -0800385 const char* GetTag() const { return tag_; }
386
Dan Albert0c055862015-03-27 11:20:14 -0700387 LogId GetId() const {
388 return id_;
389 }
390
Dan Albert58310b42015-03-13 23:06:01 -0700391 int GetError() const {
392 return error_;
393 }
394
395 std::ostream& GetBuffer() {
396 return buffer_;
397 }
398
399 std::string ToString() const {
400 return buffer_.str();
401 }
402
403 private:
404 std::ostringstream buffer_;
405 const char* const file_;
406 const unsigned int line_number_;
Dan Albert0c055862015-03-27 11:20:14 -0700407 const LogId id_;
Dan Albert58310b42015-03-13 23:06:01 -0700408 const LogSeverity severity_;
Tomasz Wasilczykc2516002017-12-18 06:30:17 -0800409 const char* const tag_;
Dan Albert58310b42015-03-13 23:06:01 -0700410 const int error_;
411
412 DISALLOW_COPY_AND_ASSIGN(LogMessageData);
413};
414
Tomasz Wasilczykc2516002017-12-18 06:30:17 -0800415LogMessage::LogMessage(const char* file, unsigned int line, LogId id, LogSeverity severity,
416 const char* tag, int error)
417 : data_(new LogMessageData(file, line, id, severity, tag, error)) {}
418
419LogMessage::LogMessage(const char* file, unsigned int line, LogId id, LogSeverity severity,
420 int error)
421 : LogMessage(file, line, id, severity, nullptr, error) {}
Dan Albert58310b42015-03-13 23:06:01 -0700422
423LogMessage::~LogMessage() {
Andreas Gampe19ff8f12016-09-23 13:31:52 -0700424 // Check severity again. This is duplicate work wrt/ LOG macros, but not LOG_STREAM.
Andreas Gampe1f5fb432016-09-23 16:37:12 -0700425 if (!WOULD_LOG(data_->GetSeverity())) {
Andreas Gampe19ff8f12016-09-23 13:31:52 -0700426 return;
427 }
428
Dan Albert58310b42015-03-13 23:06:01 -0700429 // Finish constructing the message.
430 if (data_->GetError() != -1) {
431 data_->GetBuffer() << ": " << strerror(data_->GetError());
432 }
433 std::string msg(data_->ToString());
434
Spencer Low765ae6b2015-09-17 19:36:10 -0700435 {
436 // Do the actual logging with the lock held.
Yabin Cui0c689532017-01-23 10:29:23 -0800437 std::lock_guard<std::mutex> lock(LoggingLock());
Spencer Low765ae6b2015-09-17 19:36:10 -0700438 if (msg.find('\n') == std::string::npos) {
Tomasz Wasilczykc2516002017-12-18 06:30:17 -0800439 LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(), data_->GetSeverity(),
440 data_->GetTag(), msg.c_str());
Spencer Low765ae6b2015-09-17 19:36:10 -0700441 } else {
442 msg += '\n';
443 size_t i = 0;
444 while (i < msg.size()) {
445 size_t nl = msg.find('\n', i);
446 msg[nl] = '\0';
Tomasz Wasilczykc2516002017-12-18 06:30:17 -0800447 LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(), data_->GetSeverity(),
448 data_->GetTag(), &msg[i]);
Andreas Gampeb4e32f32016-10-04 19:17:07 -0700449 // Undo the zero-termination so we can give the complete message to the aborter.
450 msg[nl] = '\n';
Spencer Low765ae6b2015-09-17 19:36:10 -0700451 i = nl + 1;
452 }
Dan Albert58310b42015-03-13 23:06:01 -0700453 }
454 }
455
456 // Abort if necessary.
457 if (data_->GetSeverity() == FATAL) {
Yabin Cui0c689532017-01-23 10:29:23 -0800458 Aborter()(msg.c_str());
Dan Albert58310b42015-03-13 23:06:01 -0700459 }
460}
461
462std::ostream& LogMessage::stream() {
463 return data_->GetBuffer();
464}
465
Tomasz Wasilczykc2516002017-12-18 06:30:17 -0800466void LogMessage::LogLine(const char* file, unsigned int line, LogId id, LogSeverity severity,
467 const char* tag, const char* message) {
Andreas Gampe3aa89362018-03-05 10:00:19 -0800468 if (tag == nullptr) {
469 std::lock_guard<std::recursive_mutex> lock(TagLock());
470 if (gDefaultTag == nullptr) {
471 gDefaultTag = new std::string(getprogname());
472 }
473 Logger()(id, severity, gDefaultTag->c_str(), file, line, message);
474 } else {
475 Logger()(id, severity, tag, file, line, message);
476 }
Dan Albert58310b42015-03-13 23:06:01 -0700477}
478
Tomasz Wasilczykc2516002017-12-18 06:30:17 -0800479void LogMessage::LogLine(const char* file, unsigned int line, LogId id, LogSeverity severity,
480 const char* message) {
481 LogLine(file, line, id, severity, nullptr, message);
482}
483
Elliott Hughes7bc87a52016-08-04 16:09:39 -0700484LogSeverity GetMinimumLogSeverity() {
485 return gMinimumLogSeverity;
486}
487
488LogSeverity SetMinimumLogSeverity(LogSeverity new_severity) {
489 LogSeverity old_severity = gMinimumLogSeverity;
490 gMinimumLogSeverity = new_severity;
491 return old_severity;
492}
493
494ScopedLogSeverity::ScopedLogSeverity(LogSeverity new_severity) {
495 old_ = SetMinimumLogSeverity(new_severity);
Dan Albert58310b42015-03-13 23:06:01 -0700496}
497
498ScopedLogSeverity::~ScopedLogSeverity() {
Elliott Hughes7bc87a52016-08-04 16:09:39 -0700499 SetMinimumLogSeverity(old_);
Dan Albert58310b42015-03-13 23:06:01 -0700500}
501
502} // namespace base
503} // namespace android