2015-03-14 07:06:01 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-05 01:09:39 +02:00
|
|
|
#if defined(_WIN32)
|
2015-05-20 07:12:06 +02:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2015-12-05 07:00:26 +01:00
|
|
|
#include "android-base/logging.h"
|
2015-03-14 07:06:01 +01:00
|
|
|
|
2016-08-05 01:09:39 +02:00
|
|
|
#include <fcntl.h>
|
2015-04-03 20:28:46 +02:00
|
|
|
#include <libgen.h>
|
2016-06-21 23:25:44 +02:00
|
|
|
#include <time.h>
|
2015-04-03 20:28:46 +02:00
|
|
|
|
|
|
|
// For getprogname(3) or program_invocation_short_name.
|
|
|
|
#if defined(__ANDROID__) || defined(__APPLE__)
|
|
|
|
#include <stdlib.h>
|
|
|
|
#elif defined(__GLIBC__)
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
|
2016-08-05 01:09:39 +02:00
|
|
|
#if defined(__linux__)
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#endif
|
|
|
|
|
2015-03-14 07:06:01 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <limits>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2015-03-27 19:20:14 +01:00
|
|
|
#include <utility>
|
2015-03-14 07:06:01 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2015-04-29 20:32:23 +02:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <mutex>
|
|
|
|
#endif
|
|
|
|
|
2015-12-05 07:00:26 +01:00
|
|
|
#include "android-base/macros.h"
|
|
|
|
#include "android-base/strings.h"
|
2015-03-14 07:06:01 +01:00
|
|
|
|
|
|
|
// Headers for LogMessage::LogLine.
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
#include <android/set_abort_message.h>
|
2016-07-29 00:15:28 +02:00
|
|
|
#include "log/log.h"
|
2015-03-14 07:06:01 +01:00
|
|
|
#else
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2015-11-11 19:02:29 +01:00
|
|
|
// For gettid.
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
#include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#elif defined(__linux__) && !defined(__ANDROID__)
|
|
|
|
#include <syscall.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2016-02-04 08:29:32 +01:00
|
|
|
#if defined(_WIN32)
|
|
|
|
typedef uint32_t thread_id;
|
|
|
|
#else
|
|
|
|
typedef pid_t thread_id;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static thread_id GetThreadId() {
|
2015-11-11 19:02:29 +01:00
|
|
|
#if defined(__BIONIC__)
|
|
|
|
return gettid();
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
return syscall(SYS_thread_selfid);
|
|
|
|
#elif defined(__linux__)
|
|
|
|
return syscall(__NR_gettid);
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
return GetCurrentThreadId();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-29 20:32:23 +02:00
|
|
|
namespace {
|
|
|
|
#ifndef _WIN32
|
|
|
|
using std::mutex;
|
|
|
|
using std::lock_guard;
|
|
|
|
|
|
|
|
#if defined(__GLIBC__)
|
|
|
|
const char* getprogname() {
|
|
|
|
return program_invocation_short_name;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
const char* getprogname() {
|
|
|
|
static bool first = true;
|
|
|
|
static char progname[MAX_PATH] = {};
|
|
|
|
|
|
|
|
if (first) {
|
2015-08-12 01:00:13 +02:00
|
|
|
CHAR longname[MAX_PATH];
|
|
|
|
DWORD nchars = GetModuleFileNameA(nullptr, longname, arraysize(longname));
|
|
|
|
if ((nchars >= arraysize(longname)) || (nchars == 0)) {
|
|
|
|
// String truncation or some other error.
|
|
|
|
strcpy(progname, "<unknown>");
|
|
|
|
} else {
|
|
|
|
strcpy(progname, basename(longname));
|
|
|
|
}
|
2015-04-29 20:32:23 +02:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return progname;
|
|
|
|
}
|
|
|
|
|
|
|
|
class mutex {
|
|
|
|
public:
|
|
|
|
mutex() {
|
2015-08-12 01:00:13 +02:00
|
|
|
InitializeCriticalSection(&critical_section_);
|
2015-04-29 20:32:23 +02:00
|
|
|
}
|
|
|
|
~mutex() {
|
2015-08-12 01:00:13 +02:00
|
|
|
DeleteCriticalSection(&critical_section_);
|
2015-04-29 20:32:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void lock() {
|
2015-08-12 01:00:13 +02:00
|
|
|
EnterCriticalSection(&critical_section_);
|
2015-04-29 20:32:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void unlock() {
|
2015-08-12 01:00:13 +02:00
|
|
|
LeaveCriticalSection(&critical_section_);
|
2015-04-29 20:32:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-08-12 01:00:13 +02:00
|
|
|
CRITICAL_SECTION critical_section_;
|
2015-04-29 20:32:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename LockT>
|
|
|
|
class lock_guard {
|
|
|
|
public:
|
|
|
|
explicit lock_guard(LockT& lock) : lock_(lock) {
|
|
|
|
lock_.lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
~lock_guard() {
|
|
|
|
lock_.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
LockT& lock_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(lock_guard);
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
} // namespace
|
|
|
|
|
2015-03-14 07:06:01 +01:00
|
|
|
namespace android {
|
|
|
|
namespace base {
|
|
|
|
|
2015-11-12 20:54:47 +01:00
|
|
|
static auto& logging_lock = *new mutex();
|
2015-03-14 07:06:01 +01:00
|
|
|
|
2015-03-27 19:20:14 +01:00
|
|
|
#ifdef __ANDROID__
|
2015-11-12 20:54:47 +01:00
|
|
|
static auto& gLogger = *new LogFunction(LogdLogger());
|
2015-03-27 19:20:14 +01:00
|
|
|
#else
|
2015-11-12 20:54:47 +01:00
|
|
|
static auto& gLogger = *new LogFunction(StderrLogger);
|
2015-03-27 19:20:14 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-03 20:28:46 +02:00
|
|
|
static bool gInitialized = false;
|
2015-03-14 07:06:01 +01:00
|
|
|
static LogSeverity gMinimumLogSeverity = INFO;
|
2015-11-12 20:54:47 +01:00
|
|
|
static auto& gProgramInvocationName = *new std::unique_ptr<std::string>();
|
2015-03-14 07:06:01 +01:00
|
|
|
|
2015-04-03 20:28:46 +02:00
|
|
|
static const char* ProgramInvocationName() {
|
|
|
|
if (gProgramInvocationName == nullptr) {
|
|
|
|
gProgramInvocationName.reset(new std::string(getprogname()));
|
|
|
|
}
|
2015-03-14 07:06:01 +01:00
|
|
|
|
2015-04-03 20:28:46 +02:00
|
|
|
return gProgramInvocationName->c_str();
|
2015-03-14 07:06:01 +01:00
|
|
|
}
|
|
|
|
|
2016-08-05 01:09:39 +02:00
|
|
|
#if defined(__linux__)
|
|
|
|
void KernelLogger(android::base::LogId, android::base::LogSeverity severity,
|
|
|
|
const char* tag, const char*, unsigned int, const char* msg) {
|
|
|
|
static constexpr int kLogSeverityToKernelLogLevel[] = {
|
|
|
|
[android::base::VERBOSE] = 7, // KERN_DEBUG (there is no verbose kernel log level)
|
|
|
|
[android::base::DEBUG] = 7, // KERN_DEBUG
|
|
|
|
[android::base::INFO] = 6, // KERN_INFO
|
|
|
|
[android::base::WARNING] = 4, // KERN_WARNING
|
|
|
|
[android::base::ERROR] = 3, // KERN_ERROR
|
|
|
|
[android::base::FATAL] = 2, // KERN_CRIT
|
|
|
|
};
|
|
|
|
static_assert(arraysize(kLogSeverityToKernelLogLevel) == android::base::FATAL + 1,
|
|
|
|
"Mismatch in size of kLogSeverityToKernelLogLevel and values in LogSeverity");
|
|
|
|
|
|
|
|
static int klog_fd = TEMP_FAILURE_RETRY(open("/dev/kmsg", O_WRONLY | O_CLOEXEC));
|
|
|
|
if (klog_fd == -1) return;
|
|
|
|
|
|
|
|
int level = kLogSeverityToKernelLogLevel[severity];
|
|
|
|
|
|
|
|
// The kernel's printk buffer is only 1024 bytes.
|
|
|
|
// TODO: should we automatically break up long lines into multiple lines?
|
|
|
|
// Or we could log but with something like "..." at the end?
|
|
|
|
char buf[1024];
|
|
|
|
size_t size = snprintf(buf, sizeof(buf), "<%d>%s: %s\n", level, tag, msg);
|
|
|
|
if (size > sizeof(buf)) {
|
|
|
|
size = snprintf(buf, sizeof(buf), "<%d>%s: %zu-byte message too long for printk\n",
|
|
|
|
level, tag, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
iovec iov[1];
|
|
|
|
iov[0].iov_base = buf;
|
|
|
|
iov[0].iov_len = size;
|
|
|
|
TEMP_FAILURE_RETRY(writev(klog_fd, iov, 1));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-27 19:20:14 +01:00
|
|
|
void StderrLogger(LogId, LogSeverity severity, const char*, const char* file,
|
|
|
|
unsigned int line, const char* message) {
|
2016-06-21 23:25:44 +02:00
|
|
|
struct tm now;
|
|
|
|
time_t t = time(nullptr);
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
localtime_s(&now, &t);
|
|
|
|
#else
|
|
|
|
localtime_r(&t, &now);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
char timestamp[32];
|
|
|
|
strftime(timestamp, sizeof(timestamp), "%m-%d %H:%M:%S", &now);
|
|
|
|
|
2015-08-12 01:00:13 +02:00
|
|
|
static const char log_characters[] = "VDIWEF";
|
|
|
|
static_assert(arraysize(log_characters) - 1 == FATAL + 1,
|
|
|
|
"Mismatch in size of log_characters and values in LogSeverity");
|
2015-03-27 19:20:14 +01:00
|
|
|
char severity_char = log_characters[severity];
|
2016-06-21 23:25:44 +02:00
|
|
|
fprintf(stderr, "%s %c %s %5d %5d %s:%u] %s\n", ProgramInvocationName(),
|
|
|
|
severity_char, timestamp, getpid(), GetThreadId(), file, line, message);
|
2015-03-27 19:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
LogdLogger::LogdLogger(LogId default_log_id) : default_log_id_(default_log_id) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogdLogger::operator()(LogId id, LogSeverity severity, const char* tag,
|
|
|
|
const char* file, unsigned int line,
|
|
|
|
const char* message) {
|
2016-08-05 01:09:39 +02:00
|
|
|
static constexpr android_LogPriority kLogSeverityToAndroidLogPriority[] = {
|
|
|
|
ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO,
|
|
|
|
ANDROID_LOG_WARN, ANDROID_LOG_ERROR, ANDROID_LOG_FATAL,
|
|
|
|
};
|
|
|
|
static_assert(arraysize(kLogSeverityToAndroidLogPriority) == FATAL + 1,
|
|
|
|
"Mismatch in size of kLogSeverityToAndroidLogPriority and values in LogSeverity");
|
|
|
|
|
2015-03-27 19:20:14 +01:00
|
|
|
int priority = kLogSeverityToAndroidLogPriority[severity];
|
|
|
|
if (id == DEFAULT) {
|
|
|
|
id = default_log_id_;
|
|
|
|
}
|
|
|
|
|
2016-08-05 01:09:39 +02:00
|
|
|
static constexpr log_id kLogIdToAndroidLogId[] = {
|
|
|
|
LOG_ID_MAX, LOG_ID_MAIN, LOG_ID_SYSTEM,
|
|
|
|
};
|
|
|
|
static_assert(arraysize(kLogIdToAndroidLogId) == SYSTEM + 1,
|
|
|
|
"Mismatch in size of kLogIdToAndroidLogId and values in LogId");
|
2015-03-27 19:20:14 +01:00
|
|
|
log_id lg_id = kLogIdToAndroidLogId[id];
|
|
|
|
|
|
|
|
if (priority == ANDROID_LOG_FATAL) {
|
|
|
|
__android_log_buf_print(lg_id, priority, tag, "%s:%u] %s", file, line,
|
|
|
|
message);
|
|
|
|
} else {
|
|
|
|
__android_log_buf_print(lg_id, priority, tag, "%s", message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void InitLogging(char* argv[], LogFunction&& logger) {
|
|
|
|
SetLogger(std::forward<LogFunction>(logger));
|
|
|
|
InitLogging(argv);
|
|
|
|
}
|
|
|
|
|
2015-03-14 07:06:01 +01:00
|
|
|
void InitLogging(char* argv[]) {
|
2015-04-03 20:28:46 +02:00
|
|
|
if (gInitialized) {
|
2015-03-14 07:06:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-03 20:28:46 +02:00
|
|
|
gInitialized = true;
|
|
|
|
|
2015-03-14 07:06:01 +01:00
|
|
|
// Stash the command line for later use. We can use /proc/self/cmdline on
|
2015-11-08 03:51:54 +01:00
|
|
|
// Linux to recover this, but we don't have that luxury on the Mac/Windows,
|
|
|
|
// and there are a couple of argv[0] variants that are commonly used.
|
2015-03-14 07:06:01 +01:00
|
|
|
if (argv != nullptr) {
|
2015-04-03 20:28:46 +02:00
|
|
|
gProgramInvocationName.reset(new std::string(basename(argv[0])));
|
2015-03-14 07:06:01 +01:00
|
|
|
}
|
2015-04-03 20:28:46 +02:00
|
|
|
|
2015-03-14 07:06:01 +01:00
|
|
|
const char* tags = getenv("ANDROID_LOG_TAGS");
|
|
|
|
if (tags == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-19 21:24:26 +01:00
|
|
|
std::vector<std::string> specs = Split(tags, " ");
|
2015-03-14 07:06:01 +01:00
|
|
|
for (size_t i = 0; i < specs.size(); ++i) {
|
|
|
|
// "tag-pattern:[vdiwefs]"
|
|
|
|
std::string spec(specs[i]);
|
|
|
|
if (spec.size() == 3 && StartsWith(spec, "*:")) {
|
|
|
|
switch (spec[2]) {
|
|
|
|
case 'v':
|
|
|
|
gMinimumLogSeverity = VERBOSE;
|
|
|
|
continue;
|
|
|
|
case 'd':
|
|
|
|
gMinimumLogSeverity = DEBUG;
|
|
|
|
continue;
|
|
|
|
case 'i':
|
|
|
|
gMinimumLogSeverity = INFO;
|
|
|
|
continue;
|
|
|
|
case 'w':
|
|
|
|
gMinimumLogSeverity = WARNING;
|
|
|
|
continue;
|
|
|
|
case 'e':
|
|
|
|
gMinimumLogSeverity = ERROR;
|
|
|
|
continue;
|
|
|
|
case 'f':
|
|
|
|
gMinimumLogSeverity = FATAL;
|
|
|
|
continue;
|
|
|
|
// liblog will even suppress FATAL if you say 's' for silent, but that's
|
|
|
|
// crazy!
|
|
|
|
case 's':
|
|
|
|
gMinimumLogSeverity = FATAL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG(FATAL) << "unsupported '" << spec << "' in ANDROID_LOG_TAGS (" << tags
|
|
|
|
<< ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 19:20:14 +01:00
|
|
|
void SetLogger(LogFunction&& logger) {
|
2015-04-29 20:32:23 +02:00
|
|
|
lock_guard<mutex> lock(logging_lock);
|
2015-03-27 19:20:14 +01:00
|
|
|
gLogger = std::move(logger);
|
|
|
|
}
|
|
|
|
|
2015-08-12 01:00:13 +02:00
|
|
|
static const char* GetFileBasename(const char* file) {
|
2015-11-08 03:51:54 +01:00
|
|
|
// We can't use basename(3) even on Unix because the Mac doesn't
|
|
|
|
// have a non-modifying basename.
|
2015-08-12 01:00:13 +02:00
|
|
|
const char* last_slash = strrchr(file, '/');
|
2015-11-08 03:51:54 +01:00
|
|
|
if (last_slash != nullptr) {
|
|
|
|
return last_slash + 1;
|
|
|
|
}
|
|
|
|
#if defined(_WIN32)
|
|
|
|
const char* last_backslash = strrchr(file, '\\');
|
|
|
|
if (last_backslash != nullptr) {
|
|
|
|
return last_backslash + 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return file;
|
2015-08-12 01:00:13 +02:00
|
|
|
}
|
|
|
|
|
2015-03-14 07:06:01 +01:00
|
|
|
// This indirection greatly reduces the stack impact of having lots of
|
|
|
|
// checks/logging in a function.
|
|
|
|
class LogMessageData {
|
|
|
|
public:
|
2015-03-27 19:20:14 +01:00
|
|
|
LogMessageData(const char* file, unsigned int line, LogId id,
|
2015-09-18 04:36:10 +02:00
|
|
|
LogSeverity severity, int error)
|
2015-08-12 01:00:13 +02:00
|
|
|
: file_(GetFileBasename(file)),
|
2015-03-27 19:20:14 +01:00
|
|
|
line_number_(line),
|
|
|
|
id_(id),
|
|
|
|
severity_(severity),
|
2015-09-18 04:36:10 +02:00
|
|
|
error_(error) {
|
2015-03-14 07:06:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* GetFile() const {
|
|
|
|
return file_;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int GetLineNumber() const {
|
|
|
|
return line_number_;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogSeverity GetSeverity() const {
|
|
|
|
return severity_;
|
|
|
|
}
|
|
|
|
|
2015-03-27 19:20:14 +01:00
|
|
|
LogId GetId() const {
|
|
|
|
return id_;
|
|
|
|
}
|
|
|
|
|
2015-03-14 07:06:01 +01:00
|
|
|
int GetError() const {
|
|
|
|
return error_;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& GetBuffer() {
|
|
|
|
return buffer_;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ToString() const {
|
|
|
|
return buffer_.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::ostringstream buffer_;
|
|
|
|
const char* const file_;
|
|
|
|
const unsigned int line_number_;
|
2015-03-27 19:20:14 +01:00
|
|
|
const LogId id_;
|
2015-03-14 07:06:01 +01:00
|
|
|
const LogSeverity severity_;
|
|
|
|
const int error_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(LogMessageData);
|
|
|
|
};
|
|
|
|
|
2015-03-27 19:20:14 +01:00
|
|
|
LogMessage::LogMessage(const char* file, unsigned int line, LogId id,
|
2015-03-14 07:06:01 +01:00
|
|
|
LogSeverity severity, int error)
|
2015-09-18 04:36:10 +02:00
|
|
|
: data_(new LogMessageData(file, line, id, severity, error)) {
|
2015-03-14 07:06:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LogMessage::~LogMessage() {
|
|
|
|
// Finish constructing the message.
|
|
|
|
if (data_->GetError() != -1) {
|
|
|
|
data_->GetBuffer() << ": " << strerror(data_->GetError());
|
|
|
|
}
|
|
|
|
std::string msg(data_->ToString());
|
|
|
|
|
2015-09-18 04:36:10 +02:00
|
|
|
{
|
|
|
|
// Do the actual logging with the lock held.
|
|
|
|
lock_guard<mutex> lock(logging_lock);
|
|
|
|
if (msg.find('\n') == std::string::npos) {
|
2015-03-27 19:20:14 +01:00
|
|
|
LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(),
|
2015-09-18 04:36:10 +02:00
|
|
|
data_->GetSeverity(), 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(), &msg[i]);
|
|
|
|
i = nl + 1;
|
|
|
|
}
|
2015-03-14 07:06:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Abort if necessary.
|
|
|
|
if (data_->GetSeverity() == FATAL) {
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
android_set_abort_message(msg.c_str());
|
|
|
|
#endif
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& LogMessage::stream() {
|
|
|
|
return data_->GetBuffer();
|
|
|
|
}
|
|
|
|
|
2015-03-27 19:20:14 +01:00
|
|
|
void LogMessage::LogLine(const char* file, unsigned int line, LogId id,
|
2015-03-27 19:20:14 +01:00
|
|
|
LogSeverity severity, const char* message) {
|
2015-04-03 20:28:46 +02:00
|
|
|
const char* tag = ProgramInvocationName();
|
2015-03-27 19:20:14 +01:00
|
|
|
gLogger(id, severity, tag, file, line, message);
|
2015-03-14 07:06:01 +01:00
|
|
|
}
|
|
|
|
|
2016-08-05 01:09:39 +02:00
|
|
|
LogSeverity GetMinimumLogSeverity() {
|
|
|
|
return gMinimumLogSeverity;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogSeverity SetMinimumLogSeverity(LogSeverity new_severity) {
|
|
|
|
LogSeverity old_severity = gMinimumLogSeverity;
|
|
|
|
gMinimumLogSeverity = new_severity;
|
|
|
|
return old_severity;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedLogSeverity::ScopedLogSeverity(LogSeverity new_severity) {
|
|
|
|
old_ = SetMinimumLogSeverity(new_severity);
|
2015-03-14 07:06:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ScopedLogSeverity::~ScopedLogSeverity() {
|
2016-08-05 01:09:39 +02:00
|
|
|
SetMinimumLogSeverity(old_);
|
2015-03-14 07:06:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace base
|
|
|
|
} // namespace android
|