Home | History | Annotate | Download | only in object_tracking
      1 /* Copyright 2017 The TensorFlow Authors. 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 
     16 #ifndef TENSORFLOW_EXAMPLES_ANDROID_JNI_OBJECT_TRACKING_LOG_STREAMING_H_
     17 #define TENSORFLOW_EXAMPLES_ANDROID_JNI_OBJECT_TRACKING_LOG_STREAMING_H_
     18 
     19 #include <android/log.h>
     20 #include <string.h>
     21 #include <ostream>
     22 #include <sstream>
     23 #include <string>
     24 
     25 // Allow this library to be built without depending on TensorFlow by
     26 // defining STANDALONE_DEMO_LIB. Otherwise TensorFlow headers will be
     27 // used.
     28 #ifdef STANDALONE_DEMO_LIB
     29 
     30 // A macro to disallow the copy constructor and operator= functions
     31 // This is usually placed in the private: declarations for a class.
     32 #define TF_DISALLOW_COPY_AND_ASSIGN(TypeName) \
     33   TypeName(const TypeName&) = delete;         \
     34   void operator=(const TypeName&) = delete
     35 
     36 #if defined(COMPILER_GCC3)
     37 #define TF_PREDICT_FALSE(x) (__builtin_expect(x, 0))
     38 #define TF_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
     39 #else
     40 #define TF_PREDICT_FALSE(x) (x)
     41 #define TF_PREDICT_TRUE(x) (x)
     42 #endif
     43 
     44 // Log levels equivalent to those defined by
     45 // third_party/tensorflow/core/platform/logging.h
     46 const int INFO = 0;            // base_logging::INFO;
     47 const int WARNING = 1;         // base_logging::WARNING;
     48 const int ERROR = 2;           // base_logging::ERROR;
     49 const int FATAL = 3;           // base_logging::FATAL;
     50 const int NUM_SEVERITIES = 4;  // base_logging::NUM_SEVERITIES;
     51 
     52 class LogMessage : public std::basic_ostringstream<char> {
     53  public:
     54   LogMessage(const char* fname, int line, int severity);
     55   ~LogMessage();
     56 
     57   // Returns the minimum log level for VLOG statements.
     58   // E.g., if MinVLogLevel() is 2, then VLOG(2) statements will produce output,
     59   // but VLOG(3) will not. Defaults to 0.
     60   static int64_t MinVLogLevel();
     61 
     62  protected:
     63   void GenerateLogMessage();
     64 
     65  private:
     66   const char* fname_;
     67   int line_;
     68   int severity_;
     69 };
     70 
     71 // LogMessageFatal ensures the process will exit in failure after
     72 // logging this message.
     73 class LogMessageFatal : public LogMessage {
     74  public:
     75   LogMessageFatal(const char* file, int line);
     76   ~LogMessageFatal();
     77 };
     78 
     79 #define _TF_LOG_INFO \
     80   ::tensorflow::internal::LogMessage(__FILE__, __LINE__, tensorflow::INFO)
     81 #define _TF_LOG_WARNING \
     82   ::tensorflow::internal::LogMessage(__FILE__, __LINE__, tensorflow::WARNING)
     83 #define _TF_LOG_ERROR \
     84   ::tensorflow::internal::LogMessage(__FILE__, __LINE__, tensorflow::ERROR)
     85 #define _TF_LOG_FATAL \
     86   ::tensorflow::internal::LogMessageFatal(__FILE__, __LINE__)
     87 
     88 #define _TF_LOG_QFATAL _TF_LOG_FATAL
     89 
     90 #define LOG(severity) _TF_LOG_##severity
     91 
     92 #define VLOG_IS_ON(lvl) ((lvl) <= LogMessage::MinVLogLevel())
     93 
     94 #define VLOG(lvl)                        \
     95   if (TF_PREDICT_FALSE(VLOG_IS_ON(lvl))) \
     96   LogMessage(__FILE__, __LINE__, ANDROID_LOG_INFO)
     97 
     98 void LogPrintF(const int severity, const char* format, ...);
     99 
    100 // Support for printf style logging.
    101 #define LOGV(...)
    102 #define LOGD(...)
    103 #define LOGI(...) LogPrintF(ANDROID_LOG_INFO, __VA_ARGS__);
    104 #define LOGW(...) LogPrintF(ANDROID_LOG_INFO, __VA_ARGS__);
    105 #define LOGE(...) LogPrintF(ANDROID_LOG_ERROR, __VA_ARGS__);
    106 
    107 #else
    108 
    109 #include "tensorflow/core/lib/strings/stringprintf.h"
    110 #include "tensorflow/core/platform/logging.h"
    111 
    112 // Support for printf style logging.
    113 #define LOGV(...)
    114 #define LOGD(...)
    115 #define LOGI(...) LOG(INFO) << tensorflow::strings::Printf(__VA_ARGS__);
    116 #define LOGW(...) LOG(INFO) << tensorflow::strings::Printf(__VA_ARGS__);
    117 #define LOGE(...) LOG(INFO) << tensorflow::strings::Printf(__VA_ARGS__);
    118 
    119 #endif
    120 
    121 #endif  // TENSORFLOW_EXAMPLES_ANDROID_JNI_OBJECT_TRACKING_LOG_STREAMING_H_
    122