1 /* Copyright 2019 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 #ifndef TENSORFLOW_LITE_MINIMAL_LOGGING_H_ 16 #define TENSORFLOW_LITE_MINIMAL_LOGGING_H_ 17 18 #include <cstdarg> 19 20 namespace tflite { 21 22 enum LogSeverity { 23 TFLITE_LOG_INFO = 0, 24 TFLITE_LOG_WARNING = 1, 25 TFLITE_LOG_ERROR = 2, 26 }; 27 28 namespace logging_internal { 29 30 // Helper class for simple platform-specific console logging. Note that we 31 // explicitly avoid the convenience of ostream-style logging to minimize binary 32 // size impact. 33 class MinimalLogger { 34 public: 35 // Logging hook that takes variadic args. 36 static void Log(LogSeverity severity, const char* format, ...); 37 38 // Logging hook that takes a formatted va_list. 39 static void VLog(LogSeverity severity, const char* format, va_list args); 40 41 private: 42 static const char* GetSeverityName(LogSeverity severity); 43 }; 44 45 } // namespace logging_internal 46 } // namespace tflite 47 48 // Convenience macro for basic internal logging in production builds. 49 // Note: This should never be used for debug-type logs, as it will *not* be 50 // stripped in release optimized builds. In general, prefer the error reporting 51 // APIs for developer-facing errors, and only use this for diagnostic output 52 // that should always be logged in user builds. 53 #define TFLITE_LOG_PROD(severity, format, ...) \ 54 tflite::logging_internal::MinimalLogger::Log(severity, format, ##__VA_ARGS__); 55 56 #endif // TENSORFLOW_LITE_MINIMAL_LOGGING_H_ 57