blob: c59a099c52f54d135ca7371f49fcf0fd3c6ee0f8 [file] [log] [blame]
Elliott Hughes13f5a582011-09-06 13:39:14 -07001/*
2 * Copyright (C) 2011 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
17#include "logging.h"
18
19#include "runtime.h"
20#include "utils.h"
21
22LogMessage::~LogMessage() {
23 if (errno_ != -1) {
24 buffer_ << ": " << strerror(errno_);
25 }
26 std::string msg(buffer_.str());
27 if (msg.find('\n') == std::string::npos) {
28 LogLine(msg.c_str());
29 } else {
30 msg += '\n';
31 size_t i = 0;
32 while (i < msg.size()) {
33 size_t nl = msg.find('\n', i);
34 msg[nl] = '\0';
35 LogLine(&msg[i]);
36 i = nl + 1;
37 }
38 }
39
40 if (severity_ == FATAL) {
41 art::Runtime::Abort(file_, line_number_);
42 }
43}
44
45std::ostream& LogMessage::stream() {
46 return buffer_;
47}