openvcdiff | 311c714 | 2008-08-26 19:29:25 +0000 | [diff] [blame] | 1 | // Copyright 2008 Google Inc. |
| 2 | // Author: Lincoln Smith |
| 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 | #ifndef OPEN_VCDIFF_LOGGING_H_ |
| 17 | #define OPEN_VCDIFF_LOGGING_H_ |
| 18 | |
| 19 | #include <config.h> |
openvcdiff@gmail.com | 732fff2 | 2010-08-04 18:00:00 +0000 | [diff] [blame] | 20 | #include <stdlib.h> // exit |
openvcdiff | 311c714 | 2008-08-26 19:29:25 +0000 | [diff] [blame] | 21 | #include <iostream> |
openvcdiff | 311c714 | 2008-08-26 19:29:25 +0000 | [diff] [blame] | 22 | |
| 23 | namespace open_vcdiff { |
| 24 | |
openvcdiff | 311c714 | 2008-08-26 19:29:25 +0000 | [diff] [blame] | 25 | extern bool g_fatal_error_occurred; |
openvcdiff | 311c714 | 2008-08-26 19:29:25 +0000 | [diff] [blame] | 26 | |
| 27 | inline void CheckFatalError() { |
| 28 | if (g_fatal_error_occurred) { |
openvcdiff@gmail.com | 732fff2 | 2010-08-04 18:00:00 +0000 | [diff] [blame] | 29 | std::cerr.flush(); |
| 30 | exit(1); |
openvcdiff | 311c714 | 2008-08-26 19:29:25 +0000 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | |
| 34 | } // namespace open_vcdiff |
| 35 | |
openvcdiff@gmail.com | 732fff2 | 2010-08-04 18:00:00 +0000 | [diff] [blame] | 36 | #define VCD_WARNING std::cerr << "WARNING: " |
| 37 | #define VCD_ERROR std::cerr << "ERROR: " |
| 38 | #ifndef NDEBUG |
| 39 | #define VCD_DFATAL open_vcdiff::g_fatal_error_occurred = true; \ |
| 40 | std::cerr << "FATAL: " |
| 41 | #else // NDEBUG |
| 42 | #define VCD_DFATAL VCD_ERROR |
| 43 | #endif // !NDEBUG |
| 44 | |
| 45 | #define VCD_ENDL std::endl; \ |
| 46 | open_vcdiff::CheckFatalError(); |
openvcdiff | 311c714 | 2008-08-26 19:29:25 +0000 | [diff] [blame] | 47 | |
| 48 | #endif // OPEN_VCDIFF_LOGGING_H_ |