blob: 84a6843352533bdd24627698a43351f2bea3c680 [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
Elliott Hughes90a33692011-08-30 13:27:07 -070017#include <sys/types.h>
18#include <unistd.h>
Elliott Hugheseb4f6142011-07-15 17:43:51 -070019
20#include <cstdio>
21#include <cstring>
Elliott Hugheseb4f6142011-07-15 17:43:51 -070022#include <iostream>
Elliott Hughes90a33692011-08-30 13:27:07 -070023
24#include "logging.h"
Elliott Hughes90a33692011-08-30 13:27:07 -070025#include "stringprintf.h"
Elliott Hughes42ee1422011-09-06 12:33:32 -070026#include "utils.h"
Elliott Hugheseb4f6142011-07-15 17:43:51 -070027
Elliott Hughesf5a7a472011-10-07 14:31:02 -070028namespace art {
29
Elliott Hugheseb4f6142011-07-15 17:43:51 -070030LogMessage::LogMessage(const char* file, int line, LogSeverity severity, int error)
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070031 : data_(new LogMessageData(line, severity, error)) {
Elliott Hugheseb4f6142011-07-15 17:43:51 -070032 const char* last_slash = strrchr(file, '/');
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070033 data_->file = (last_slash == NULL) ? file : last_slash + 1;
Elliott Hugheseb4f6142011-07-15 17:43:51 -070034}
35
Elliott Hughesc1e041a2012-02-06 18:27:24 -080036void LogMessage::LogLine(const char* message) {
Elliott Hughes72395bf2012-04-24 13:45:26 -070037 std::ostream& os(std::cerr);
38 os << "VDIWEFF"[data_->severity] << ' '
39 << StringPrintf("%5d %5d", getpid(), ::art::GetTid()) << ' '
40 << data_->file << ':' << data_->line_number << "] " << message << std::endl;
Elliott Hugheseb4f6142011-07-15 17:43:51 -070041}
Elliott Hughesf5a7a472011-10-07 14:31:02 -070042
43} // namespace art