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 
16 #include <android/log.h>
17 
18 #include <cstdio>
19 
20 #include "tensorflow/lite/minimal_logging.h"
21 
22 namespace tflite {
23 namespace logging_internal {
24 namespace {
25 
GetPlatformSeverity(LogSeverity severity)26 int GetPlatformSeverity(LogSeverity severity) {
27   switch (severity) {
28     case TFLITE_LOG_INFO:
29       return ANDROID_LOG_INFO;
30     case TFLITE_LOG_WARNING:
31       return ANDROID_LOG_WARN;
32     case TFLITE_LOG_ERROR:
33       return ANDROID_LOG_ERROR;
34     default:
35       return ANDROID_LOG_DEBUG;
36   }
37 }
38 
39 }  // namespace
40 
LogFormatted(LogSeverity severity,const char * format,va_list args)41 void MinimalLogger::LogFormatted(LogSeverity severity, const char* format,
42                                  va_list args) {
43   // First log to Android's explicit log(cat) API.
44   va_list args_copy;
45   va_copy(args_copy, args);
46   __android_log_vprint(GetPlatformSeverity(severity), "tflite", format,
47                        args_copy);
48   va_end(args_copy);
49 
50   // Also print to stderr for standard console applications.
51   fprintf(stderr, "%s: ", GetSeverityName(severity));
52   va_copy(args_copy, args);
53   vfprintf(stderr, format, args_copy);
54   va_end(args_copy);
55   fputc('\n', stderr);
56 }
57 
58 }  // namespace logging_internal
59 }  // namespace tflite
60