Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
Elliott Hughes | eb4f614 | 2011-07-15 17:43:51 -0700 | [diff] [blame] | 16 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 17 | #include <sys/types.h> |
| 18 | #include <unistd.h> |
Elliott Hughes | eb4f614 | 2011-07-15 17:43:51 -0700 | [diff] [blame] | 19 | |
| 20 | #include <cstdio> |
| 21 | #include <cstring> |
Elliott Hughes | eb4f614 | 2011-07-15 17:43:51 -0700 | [diff] [blame] | 22 | #include <iostream> |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 23 | |
| 24 | #include "logging.h" |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 25 | #include "stringprintf.h" |
Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 26 | #include "utils.h" |
Elliott Hughes | eb4f614 | 2011-07-15 17:43:51 -0700 | [diff] [blame] | 27 | |
Elliott Hughes | f5a7a47 | 2011-10-07 14:31:02 -0700 | [diff] [blame] | 28 | namespace art { |
| 29 | |
Elliott Hughes | eb4f614 | 2011-07-15 17:43:51 -0700 | [diff] [blame] | 30 | LogMessage::LogMessage(const char* file, int line, LogSeverity severity, int error) |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 31 | : data_(new LogMessageData(line, severity, error)) { |
Elliott Hughes | eb4f614 | 2011-07-15 17:43:51 -0700 | [diff] [blame] | 32 | const char* last_slash = strrchr(file, '/'); |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 33 | data_->file = (last_slash == NULL) ? file : last_slash + 1; |
Elliott Hughes | eb4f614 | 2011-07-15 17:43:51 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Elliott Hughes | c1e041a | 2012-02-06 18:27:24 -0800 | [diff] [blame] | 36 | void LogMessage::LogLine(const char* message) { |
Elliott Hughes | 9ee5f9c | 2012-02-03 18:33:16 -0800 | [diff] [blame] | 37 | std::cerr << "VDIWEFF"[data_->severity] << ' ' |
Elliott Hughes | 3ea7e99 | 2011-10-11 18:48:16 -0700 | [diff] [blame] | 38 | << StringPrintf("%5d %5d", getpid(), ::art::GetTid()) << ' ' |
Elliott Hughes | c1e041a | 2012-02-06 18:27:24 -0800 | [diff] [blame] | 39 | << data_->file << ':' << data_->line_number << "] " << message << std::endl; |
Elliott Hughes | eb4f614 | 2011-07-15 17:43:51 -0700 | [diff] [blame] | 40 | } |
Elliott Hughes | f5a7a47 | 2011-10-07 14:31:02 -0700 | [diff] [blame] | 41 | |
| 42 | } // namespace art |