blob: eed58b83ffc4cf77ad323d4ba867c9f3970f1f59 [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
17#ifndef AAPT_LOGGER_H
18#define AAPT_LOGGER_H
19
20#include "Source.h"
Adam Lesinski90959882015-07-06 18:09:18 -070021#include "StringPiece.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080022
23#include <memory>
24#include <ostream>
25#include <string>
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080026
27namespace aapt {
28
29struct Log {
30 Log(std::ostream& out, std::ostream& err);
31 Log(const Log& rhs) = delete;
32
33 std::ostream& out;
34 std::ostream& err;
35};
36
37class Logger {
38public:
39 static void setLog(const std::shared_ptr<Log>& log);
40
41 static std::ostream& error();
42 static std::ostream& error(const Source& source);
43 static std::ostream& error(const SourceLine& sourceLine);
44
45 static std::ostream& warn();
46 static std::ostream& warn(const Source& source);
47 static std::ostream& warn(const SourceLine& sourceLine);
48
49 static std::ostream& note();
50 static std::ostream& note(const Source& source);
51 static std::ostream& note(const SourceLine& sourceLine);
52
53private:
54 static std::shared_ptr<Log> sLog;
55};
56
57class SourceLogger {
58public:
59 SourceLogger(const Source& source);
60
61 std::ostream& error();
62 std::ostream& error(size_t line);
63
64 std::ostream& warn();
65 std::ostream& warn(size_t line);
66
67 std::ostream& note();
68 std::ostream& note(size_t line);
69
70private:
71 Source mSource;
72};
73
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080074} // namespace aapt
75
76#endif // AAPT_LOGGER_H