blob: 56e2dae01d49a0307ce9d79458e2d69b33c20fe1 [file] [log] [blame]
Elliott Hugheseb4f6142011-07-15 17:43:51 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2// Author: enh@google.com (Elliott Hughes)
3
4#include "logging.h"
5
6#include <iostream>
7#include <unistd.h>
8
9#include "cutils/log.h"
Elliott Hughesffe67362011-07-17 12:09:27 -070010#include "runtime.h"
Elliott Hugheseb4f6142011-07-15 17:43:51 -070011
12static const int kLogSeverityToAndroidLogPriority[] = {
13 ANDROID_LOG_INFO, ANDROID_LOG_WARN, ANDROID_LOG_ERROR, ANDROID_LOG_FATAL
14};
15
16LogMessage::LogMessage(const char* file, int line, LogSeverity severity, int error)
Elliott Hughesffe67362011-07-17 12:09:27 -070017: file_(file), line_(line), severity_(severity), errno_(error)
Elliott Hugheseb4f6142011-07-15 17:43:51 -070018{
19}
20
21LogMessage::~LogMessage() {
22 if (errno_ != -1) {
Elliott Hughesffe67362011-07-17 12:09:27 -070023 stream() << ": " << strerror(errno_);
Elliott Hugheseb4f6142011-07-15 17:43:51 -070024 }
25 int priority = kLogSeverityToAndroidLogPriority[severity_];
26 LOG_PRI(priority, LOG_TAG, "%s", buffer_.str().c_str());
27 if (severity_ == FATAL) {
Elliott Hughesffe67362011-07-17 12:09:27 -070028 art::Runtime::Abort(file_, line_);
Elliott Hugheseb4f6142011-07-15 17:43:51 -070029 }
30}
31
32std::ostream& LogMessage::stream() {
33 return buffer_;
34}