blob: 62f2422e1d5c402dfd0d2efeb7659b07a90d3713 [file] [log] [blame]
Shinichiro Hamajie9f7e672015-07-03 15:57:45 +09001// Copyright 2015 Google Inc. All rights reserved
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// +build ignore
16
17#include "log.h"
18
Dan Willemsene41c7552017-02-22 14:31:16 -080019#include "flags.h"
20#include "strutil.h"
21
22#define BOLD "\033[1m"
23#define RESET "\033[0m"
24#define MAGENTA "\033[35m"
25#define RED "\033[31m"
26
27void ColorErrorLog(const char* file, int line, const char* msg) {
28 if (file == nullptr) {
29 ERROR("%s", msg);
30 return;
31 }
32
33 if (g_flags.color_warnings) {
34 StringPiece filtered = TrimPrefix(msg, "*** ");
35
Dan Willemsen3ce083f2017-10-11 22:17:48 -070036 ERROR(BOLD "%s:%d: " RED "error: " RESET BOLD "%s" RESET, file, line,
37 filtered.as_string().c_str());
Dan Willemsene41c7552017-02-22 14:31:16 -080038 } else {
39 ERROR("%s:%d: %s", file, line, msg);
40 }
41}
42
43void ColorWarnLog(const char* file, int line, const char* msg) {
44 if (file == nullptr) {
45 fprintf(stderr, "%s\n", msg);
46 return;
47 }
48
49 if (g_flags.color_warnings) {
50 StringPiece filtered = TrimPrefix(msg, "*warning*: ");
51 filtered = TrimPrefix(filtered, "warning: ");
52
Dan Willemsen3ce083f2017-10-11 22:17:48 -070053 fprintf(stderr,
54 BOLD "%s:%d: " MAGENTA "warning: " RESET BOLD "%s" RESET "\n", file,
55 line, filtered.as_string().c_str());
Dan Willemsene41c7552017-02-22 14:31:16 -080056 } else {
57 fprintf(stderr, "%s:%d: %s\n", file, line, msg);
58 }
59}
60
Shinichiro Hamajie9f7e672015-07-03 15:57:45 +090061bool g_log_no_exit;
62string* g_last_error;