blob: 384718567984d7b8d9748e06cf75fe1978e27a76 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
2 * Copyright (C) 2015 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#include "Logger.h"
17#include "Source.h"
18
19#include <memory>
20#include <iostream>
21
22namespace aapt {
23
24Log::Log(std::ostream& _out, std::ostream& _err) : out(_out), err(_err) {
25}
26
27std::shared_ptr<Log> Logger::sLog(std::make_shared<Log>(std::cerr, std::cerr));
28
29void Logger::setLog(const std::shared_ptr<Log>& log) {
30 sLog = log;
31}
32
33std::ostream& Logger::error() {
34 return sLog->err << "error: ";
35}
36
37std::ostream& Logger::error(const Source& source) {
38 return sLog->err << source << ": error: ";
39}
40
41std::ostream& Logger::error(const SourceLine& source) {
42 return sLog->err << source << ": error: ";
43}
44
45std::ostream& Logger::warn() {
46 return sLog->err << "warning: ";
47}
48
49std::ostream& Logger::warn(const Source& source) {
50 return sLog->err << source << ": warning: ";
51}
52
53std::ostream& Logger::warn(const SourceLine& source) {
54 return sLog->err << source << ": warning: ";
55}
56
57std::ostream& Logger::note() {
58 return sLog->out << "note: ";
59}
60
61std::ostream& Logger::note(const Source& source) {
62 return sLog->err << source << ": note: ";
63}
64
65std::ostream& Logger::note(const SourceLine& source) {
66 return sLog->err << source << ": note: ";
67}
68
69SourceLogger::SourceLogger(const Source& source)
70: mSource(source) {
71}
72
73std::ostream& SourceLogger::error() {
74 return Logger::error(mSource);
75}
76
77std::ostream& SourceLogger::error(size_t line) {
78 return Logger::error(SourceLine{ mSource.path, line });
79}
80
81std::ostream& SourceLogger::warn() {
82 return Logger::warn(mSource);
83}
84
85std::ostream& SourceLogger::warn(size_t line) {
86 return Logger::warn(SourceLine{ mSource.path, line });
87}
88
89std::ostream& SourceLogger::note() {
90 return Logger::note(mSource);
91}
92
93std::ostream& SourceLogger::note(size_t line) {
94 return Logger::note(SourceLine{ mSource.path, line });
95}
96
97} // namespace aapt