1 | /* Copyright 2020 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 | #include "tensorflow/c/logging.h" |
16 | |
17 | #include "tensorflow/core/platform/logging.h" |
18 | #include "tensorflow/core/platform/stringprintf.h" |
19 | |
20 | static ::tensorflow::string BuildMessage(const char* fmt, va_list args) { |
21 | ::tensorflow::string message; |
22 | ::tensorflow::strings::Appendv(&message, fmt, args); |
23 | return message; |
24 | } |
25 | |
26 | void TF_Log(TF_LogLevel level, const char* fmt, ...) { |
27 | if (level < TF_INFO || level > TF_FATAL) return; |
28 | va_list args; |
29 | va_start(args, fmt); |
30 | auto message = BuildMessage(fmt, args); |
31 | va_end(args); |
32 | switch (level) { |
33 | case TF_INFO: |
34 | LOG(INFO) << message; |
35 | break; |
36 | case TF_WARNING: |
37 | LOG(WARNING) << message; |
38 | break; |
39 | case TF_ERROR: |
40 | LOG(ERROR) << message; |
41 | break; |
42 | case TF_FATAL: |
43 | LOG(FATAL) << message; |
44 | break; |
45 | } |
46 | } |
47 | |
48 | void TF_VLog(int level, const char* fmt, ...) { |
49 | va_list args; |
50 | va_start(args, fmt); |
51 | auto message = BuildMessage(fmt, args); |
52 | va_end(args); |
53 | VLOG(level) << message; |
54 | } |
55 | |
56 | void TF_DVLog(int level, const char* fmt, ...) { |
57 | va_list args; |
58 | va_start(args, fmt); |
59 | auto message = BuildMessage(fmt, args); |
60 | va_end(args); |
61 | DVLOG(level) << message; |
62 | } |
63 | |