blob: 9b1ac58461facd807897e49cabb28e548274d43d [file] [log] [blame]
Elliott Hughes42ee1422011-09-06 12:33:32 -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 */
Elliott Hugheseb4f6142011-07-15 17:43:51 -070016
17#include "logging.h"
18
Elliott Hugheseb4f6142011-07-15 17:43:51 -070019#include <unistd.h>
20
Elliott Hughese222ee02012-12-13 14:41:43 -080021#include <iostream>
22
23#include "base/stringprintf.h"
Elliott Hugheseb4f6142011-07-15 17:43:51 -070024#include "cutils/log.h"
25
Elliott Hughesf5a7a472011-10-07 14:31:02 -070026namespace art {
27
Elliott Hugheseb4f6142011-07-15 17:43:51 -070028static const int kLogSeverityToAndroidLogPriority[] = {
Elliott Hughes9ee5f9c2012-02-03 18:33:16 -080029 ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO, ANDROID_LOG_WARN,
30 ANDROID_LOG_ERROR, ANDROID_LOG_FATAL, ANDROID_LOG_FATAL
Elliott Hugheseb4f6142011-07-15 17:43:51 -070031};
32
Brian Carlstromaf1b8922012-11-27 15:19:57 -080033void LogMessage::LogLine(const LogMessageData& data, const char* message) {
Elliott Hughes0d39c122012-06-06 16:41:17 -070034 const char* tag = ProgramInvocationShortName();
Brian Carlstromaf1b8922012-11-27 15:19:57 -080035 int priority = kLogSeverityToAndroidLogPriority[data.severity];
Elliott Hughesc1e041a2012-02-06 18:27:24 -080036 if (priority == ANDROID_LOG_FATAL) {
Brian Carlstromaf1b8922012-11-27 15:19:57 -080037 LOG_PRI(priority, tag, "%s:%d] %s", data.file, data.line_number, message);
Elliott Hughesc1e041a2012-02-06 18:27:24 -080038 } else {
Elliott Hughes0d39c122012-06-06 16:41:17 -070039 LOG_PRI(priority, tag, "%s", message);
Elliott Hughesc1e041a2012-02-06 18:27:24 -080040 }
Elliott Hugheseb4f6142011-07-15 17:43:51 -070041}
Elliott Hughesf5a7a472011-10-07 14:31:02 -070042
43} // namespace art