tesseract v5.3.3.20231005
log.h
Go to the documentation of this file.
1
2// File: log.h
3// Description: Include for custom log message for unittest for tesseract.
4// based on
5// https://stackoverflow.com/questions/16491675/how-to-send-custom-message-in-google-c-testing-framework
6//
7// Licensed under the Apache License, Version 2.0 (the "License");
8// you may not use this file except in compliance with the License.
9// You may obtain a copy of the License at
10// http://www.apache.org/licenses/LICENSE-2.0
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
17
18#ifndef TESSERACT_UNITTEST_LOG_H_
19#define TESSERACT_UNITTEST_LOG_H_
20
21// This is a minimal implementation of the TensorFlow logging API
22// which is sufficient for the Tesseract unit tests.
23
24// See tensorflow/core/platform/default/logging.h for the original code.
25
26#include <iostream>
27
29
30// Avoid conflict with logging.h from TensorFlow.
31#undef LOG
32
33static inline std::ostream &LOG(enum LogLevel level) {
34 switch (level) {
35 case INFO:
36 std::cout << "[INFO] ";
37 break;
38 case WARNING:
39 std::cout << "[WARN] ";
40 break;
41 case ERROR:
42 std::cout << "[ERROR] ";
43 break;
44 case FATAL:
45 std::cout << "[FATAL] ";
46 break;
47 }
48 return std::cout;
49}
50
51// Avoid conflict with logging.h from TensorFlow.
52#undef QCHECK
53
54// https://github.com/google/ion/blob/master/ion/base/logging.h
55static inline std::ostream &QCHECK(bool condition) {
56 if (condition) {
57 static std::ostream null_stream(nullptr);
58 return null_stream;
59 }
60 return std::cout;
61}
62
63#endif // TESSERACT_UNITTEST_LOG_H_
@ LOG
LogLevel
Definition: log.h:28
@ ERROR
Definition: log.h:28
@ FATAL
Definition: log.h:28
@ INFO
Definition: log.h:28
@ WARNING
Definition: log.h:28