Shinichiro Hamaji | e9f7e67 | 2015-07-03 15:57:45 +0900 | [diff] [blame] | 1 | // 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 Willemsen | e41c755 | 2017-02-22 14:31:16 -0800 | [diff] [blame] | 19 | #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 | |
| 27 | void 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 | |
| 36 | ERROR(BOLD "%s:%d: " RED "error: " RESET BOLD "%s" RESET, |
| 37 | file, line, filtered.as_string().c_str()); |
| 38 | } else { |
| 39 | ERROR("%s:%d: %s", file, line, msg); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | void 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 | |
| 53 | fprintf(stderr, BOLD "%s:%d: " MAGENTA "warning: " RESET BOLD "%s" RESET "\n", |
| 54 | file, line, filtered.as_string().c_str()); |
| 55 | } else { |
| 56 | fprintf(stderr, "%s:%d: %s\n", file, line, msg); |
| 57 | } |
| 58 | } |
| 59 | |
Shinichiro Hamaji | e9f7e67 | 2015-07-03 15:57:45 +0900 | [diff] [blame] | 60 | bool g_log_no_exit; |
| 61 | string* g_last_error; |