tesseract  5.0.0-alpha-619-ge9db
log.h
Go to the documentation of this file.
1 // 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 
28 enum LogLevel {
30 };
31 
32 // Avoid conflict with logging.h from TensorFlow.
33 #undef LOG
34 
35 static inline std::ostream& LOG(enum LogLevel level)
36 {
37  switch (level) {
38  case INFO:
39  std::cout << "[INFO] ";
40  break;
41  case WARNING:
42  std::cout << "[WARN] ";
43  break;
44  case ERROR:
45  std::cout << "[ERROR] ";
46  break;
47  case FATAL:
48  std::cout << "[FATAL] ";
49  break;
50  }
51  return std::cout;
52 }
53 
54 // Avoid conflict with logging.h from TensorFlow.
55 #undef QCHECK
56 
57 // https://github.com/google/ion/blob/master/ion/base/logging.h
58 static inline std::ostream& QCHECK(bool condition)
59 {
60  if (condition) {
61  static std::ostream null_stream(nullptr);
62  return null_stream;
63  }
64  return std::cout;
65 }
66 
67 #endif // TESSERACT_UNITTEST_LOG_H_
INFO
Definition: log.h:29
FATAL
Definition: log.h:29
LogLevel
LogLevel
Definition: log.h:28
ERROR
Definition: log.h:29
WARNING
Definition: log.h:29
LOG
Definition: cleanapi_test.cc:19