summaryrefslogtreecommitdiff
path: root/src/logging_android.cc
blob: 8acb6ef23b16ba33576266554d6ef9ad21d0d20c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2011 Google Inc. All Rights Reserved.

#include "logging.h"

#include <iostream>
#include <unistd.h>

#include "cutils/log.h"
#include "runtime.h"

static const int kLogSeverityToAndroidLogPriority[] = {
  ANDROID_LOG_INFO, ANDROID_LOG_WARN, ANDROID_LOG_ERROR, ANDROID_LOG_FATAL
};

LogMessage::LogMessage(const char* file, int line, LogSeverity severity, int error)
: file_(file), line_(line), severity_(severity), errno_(error)
{
}

LogMessage::~LogMessage() {
  if (errno_ != -1) {
    stream() << ": " << strerror(errno_);
  }
  int priority = kLogSeverityToAndroidLogPriority[severity_];
  LOG_PRI(priority, LOG_TAG, "%s", buffer_.str().c_str());
  if (severity_ == FATAL) {
    art::Runtime::Abort(file_, line_);
  }
}

std::ostream& LogMessage::stream() {
  return buffer_;
}