1 /* Copyright 2015 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_CORE_PLATFORM_DEFAULT_LOGGING_H_
17 #define TENSORFLOW_CORE_PLATFORM_DEFAULT_LOGGING_H_
18
19 // IWYU pragma: private, include "third_party/tensorflow/core/platform/logging.h"
20 // IWYU pragma: friend third_party/tensorflow/core/platform/logging.h
21
22 #include <atomic>
23 #include <limits>
24 #include <memory>
25 #include <sstream>
26
27 #ifdef TF_ANDROID_ENABLE_LOGSINK
28 #include "absl/base/log_severity.h"
29 #include "absl/strings/string_view.h"
30 #endif // TF_ANDROID_ENABLE_LOGSINK
31 #include "tensorflow/core/platform/macros.h"
32 #include "tensorflow/core/platform/types.h"
33
34 // TODO(mrry): Prevent this Windows.h #define from leaking out of our headers.
35 #undef ERROR
36
37 namespace tensorflow {
38 const int INFO = 0; // base_logging::INFO;
39 const int WARNING = 1; // base_logging::WARNING;
40 const int ERROR = 2; // base_logging::ERROR;
41 const int FATAL = 3; // base_logging::FATAL;
42 const int NUM_SEVERITIES = 4; // base_logging::NUM_SEVERITIES;
43
44 namespace internal {
45
46 class LogMessage : public std::basic_ostringstream<char> {
47 public:
48 LogMessage(const char* fname, int line, int severity);
49 ~LogMessage() override;
50
51 // Change the location of the log message.
52 LogMessage& AtLocation(const char* fname, int line);
53
54 // Returns the minimum log level for VLOG statements.
55 // E.g., if MinVLogLevel() is 2, then VLOG(2) statements will produce output,
56 // but VLOG(3) will not. Defaults to 0.
57 static int64 MinVLogLevel();
58
59 // Returns whether VLOG level lvl is activated for the file fname.
60 //
61 // E.g. if the environment variable TF_CPP_VMODULE contains foo=3 and fname is
62 // foo.cc and lvl is <= 3, this will return true. It will also return true if
63 // the level is lower or equal to TF_CPP_MIN_VLOG_LEVEL (default zero).
64 //
65 // It is expected that the result of this query will be cached in the VLOG-ing
66 // call site to avoid repeated lookups. This routine performs a hash-map
67 // access against the VLOG-ing specification provided by the env var.
68 static bool VmoduleActivated(const char* fname, int level);
69
70 protected:
71 void GenerateLogMessage();
72
73 private:
74 const char* fname_;
75 int line_;
76 int severity_;
77 };
78
79 // Uses the lower operator & precedence to voidify a LogMessage reference, so
80 // that the ternary VLOG() implementation is balanced, type wise.
81 struct Voidifier {
82 template <typename T>
83 void operator&(const T&)const {}
84 };
85
86 // LogMessageFatal ensures the process will exit in failure after
87 // logging this message.
88 class LogMessageFatal : public LogMessage {
89 public:
90 LogMessageFatal(const char* file, int line) TF_ATTRIBUTE_COLD;
91 TF_ATTRIBUTE_NORETURN ~LogMessageFatal() override;
92 };
93
94 // LogMessageNull supports the DVLOG macro by simply dropping any log messages.
95 class LogMessageNull : public std::basic_ostringstream<char> {
96 public:
LogMessageNull()97 LogMessageNull() {}
~LogMessageNull()98 ~LogMessageNull() override {}
99 };
100
101 #define _TF_LOG_INFO \
102 ::tensorflow::internal::LogMessage(__FILE__, __LINE__, ::tensorflow::INFO)
103 #define _TF_LOG_WARNING \
104 ::tensorflow::internal::LogMessage(__FILE__, __LINE__, ::tensorflow::WARNING)
105 #define _TF_LOG_ERROR \
106 ::tensorflow::internal::LogMessage(__FILE__, __LINE__, ::tensorflow::ERROR)
107 #define _TF_LOG_FATAL \
108 ::tensorflow::internal::LogMessageFatal(__FILE__, __LINE__)
109
110 #define _TF_LOG_QFATAL _TF_LOG_FATAL
111
112 #define LOG(severity) _TF_LOG_##severity
113
114 #ifdef IS_MOBILE_PLATFORM
115
116 // Turn VLOG off when under mobile devices for considerations of binary size.
117 #define VLOG_IS_ON(lvl) ((lvl) <= 0)
118
119 #else
120
121 // Otherwise, set TF_CPP_MIN_VLOG_LEVEL environment to update minimum log level
122 // of VLOG, or TF_CPP_VMODULE to set the minimum log level for individual
123 // translation units.
124 #define VLOG_IS_ON(lvl) \
125 (([](int level, const char* fname) { \
126 static const bool vmodule_activated = \
127 ::tensorflow::internal::LogMessage::VmoduleActivated(fname, level); \
128 return vmodule_activated; \
129 })(lvl, __FILE__))
130
131 #endif
132
133 #define VLOG(level) \
134 TF_PREDICT_TRUE(!VLOG_IS_ON(level)) \
135 ? (void)0 \
136 : ::tensorflow::internal::Voidifier() & \
137 ::tensorflow::internal::LogMessage(__FILE__, __LINE__, \
138 tensorflow::INFO)
139
140 // `DVLOG` behaves like `VLOG` in debug mode (i.e. `#ifndef NDEBUG`).
141 // Otherwise, it compiles away and does nothing.
142 #ifndef NDEBUG
143 #define DVLOG VLOG
144 #else
145 #define DVLOG(verbose_level) \
146 while (false && (verbose_level) > 0) ::tensorflow::internal::LogMessageNull()
147 #endif
148
149 class LogEveryNState {
150 public:
151 bool ShouldLog(int n);
counter()152 uint32_t counter() { return counter_.load(std::memory_order_relaxed); }
153
154 private:
155 std::atomic<uint32> counter_{0};
156 };
157
158 class LogFirstNState {
159 public:
160 bool ShouldLog(int n);
counter()161 uint32 counter() { return counter_.load(std::memory_order_relaxed); }
162
163 private:
164 std::atomic<uint32> counter_{0};
165 };
166
167 class LogEveryPow2State {
168 public:
169 bool ShouldLog(int ignored);
counter()170 uint32 counter() { return counter_.load(std::memory_order_relaxed); }
171
172 private:
173 std::atomic<uint32> counter_{0};
174 };
175
176 #ifdef TF_ANDROID_ENABLE_LOG_EVERY_N_SECONDS
177 class LogEveryNSecState {
178 public:
179 bool ShouldLog(double seconds);
counter()180 uint32 counter() { return counter_.load(std::memory_order_relaxed); }
181
182 private:
183 std::atomic<uint32> counter_{0};
184 // Cycle count according to CycleClock that we should next log at.
185 std::atomic<int64> next_log_time_cycles_{0};
186 };
187 #endif
188
189 // This macro has a lot going on!
190 //
191 // * A local static (`logging_internal_stateful_condition_state`) is
192 // declared in a scope such that each `LOG_EVERY_N` (etc.) line has its own
193 // state.
194 // * `COUNTER`, the third variable, is used to support `<< COUNTER`. It is not
195 // mangled, so shadowing can be a problem, albeit more of a
196 // shoot-yourself-in-the-foot one. Don't name your variables `COUNTER`.
197 // * A single for loop can declare state and also test
198 // `condition && state.ShouldLog()`, but there's no way to constrain it to run
199 // only once (or not at all) without declaring another variable. The outer
200 // for-loop declares this variable (`do_log`).
201 // * Using for loops instead of if statements means there's no risk of an
202 // ambiguous dangling else statement.
203 #define LOGGING_INTERNAL_STATEFUL_CONDITION(kind, condition, arg) \
204 for (bool logging_internal_stateful_condition_do_log(condition); \
205 logging_internal_stateful_condition_do_log; \
206 logging_internal_stateful_condition_do_log = false) \
207 for (static ::tensorflow::internal::Log##kind##State \
208 logging_internal_stateful_condition_state; \
209 logging_internal_stateful_condition_do_log && \
210 logging_internal_stateful_condition_state.ShouldLog(arg); \
211 logging_internal_stateful_condition_do_log = false) \
212 for (const uint32_t COUNTER ABSL_ATTRIBUTE_UNUSED = \
213 logging_internal_stateful_condition_state.counter(); \
214 logging_internal_stateful_condition_do_log; \
215 logging_internal_stateful_condition_do_log = false)
216
217 // An instance of `LOG_EVERY_N` increments a hidden zero-initialized counter
218 // every time execution passes through it and logs the specified message when
219 // the counter's value is a multiple of `n`, doing nothing otherwise. Each
220 // instance has its own counter. The counter's value can be logged by streaming
221 // the symbol `COUNTER`. `LOG_EVERY_N` is thread-safe.
222 // Example:
223 //
224 // for (const auto& user : all_users) {
225 // LOG_EVERY_N(INFO, 1000) << "Processing user #" << COUNTER;
226 // ProcessUser(user);
227 // }
228 #define LOG_EVERY_N(severity, n) \
229 LOGGING_INTERNAL_STATEFUL_CONDITION(EveryN, true, n) \
230 LOG(severity)
231 // `LOG_FIRST_N` behaves like `LOG_EVERY_N` except that the specified message is
232 // logged when the counter's value is less than `n`. `LOG_FIRST_N` is
233 // thread-safe.
234 #define LOG_FIRST_N(severity, n) \
235 LOGGING_INTERNAL_STATEFUL_CONDITION(FirstN, true, n) \
236 LOG(severity)
237 // `LOG_EVERY_POW_2` behaves like `LOG_EVERY_N` except that the specified
238 // message is logged when the counter's value is a power of 2.
239 // `LOG_EVERY_POW_2` is thread-safe.
240 #define LOG_EVERY_POW_2(severity) \
241 LOGGING_INTERNAL_STATEFUL_CONDITION(EveryPow2, true, 0) \
242 LOG(severity)
243 // An instance of `LOG_EVERY_N_SEC` uses a hidden state variable to log the
244 // specified message at most once every `n_seconds`. A hidden counter of
245 // executions (whether a message is logged or not) is also maintained and can be
246 // logged by streaming the symbol `COUNTER`. `LOG_EVERY_N_SEC` is thread-safe.
247 // Example:
248 //
249 // LOG_EVERY_N_SEC(INFO, 2.5) << "Got " << COUNTER << " cookies so far";
250 #define LOG_EVERY_N_SEC(severity, n_seconds) \
251 LOGGING_INTERNAL_STATEFUL_CONDITION(EveryNSec, true, n_seconds) \
252 LOG(severity)
253
254 // CHECK dies with a fatal error if condition is not true. It is *not*
255 // controlled by NDEBUG, so the check will be executed regardless of
256 // compilation mode. Therefore, it is safe to do things like:
257 // CHECK(fp->Write(x) == 4)
258 #define CHECK(condition) \
259 if (TF_PREDICT_FALSE(!(condition))) \
260 LOG(FATAL) << "Check failed: " #condition " "
261
262 // Function is overloaded for integral types to allow static const
263 // integrals declared in classes and not defined to be used as arguments to
264 // CHECK* macros. It's not encouraged though.
265 template <typename T>
GetReferenceableValue(const T & t)266 inline const T& GetReferenceableValue(const T& t) {
267 return t;
268 }
GetReferenceableValue(char t)269 inline char GetReferenceableValue(char t) { return t; }
GetReferenceableValue(unsigned char t)270 inline unsigned char GetReferenceableValue(unsigned char t) { return t; }
GetReferenceableValue(signed char t)271 inline signed char GetReferenceableValue(signed char t) { return t; }
GetReferenceableValue(short t)272 inline short GetReferenceableValue(short t) { return t; }
GetReferenceableValue(unsigned short t)273 inline unsigned short GetReferenceableValue(unsigned short t) { return t; }
GetReferenceableValue(int t)274 inline int GetReferenceableValue(int t) { return t; }
GetReferenceableValue(unsigned int t)275 inline unsigned int GetReferenceableValue(unsigned int t) { return t; }
GetReferenceableValue(long t)276 inline long GetReferenceableValue(long t) { return t; }
GetReferenceableValue(unsigned long t)277 inline unsigned long GetReferenceableValue(unsigned long t) { return t; }
GetReferenceableValue(long long t)278 inline long long GetReferenceableValue(long long t) { return t; }
GetReferenceableValue(unsigned long long t)279 inline unsigned long long GetReferenceableValue(unsigned long long t) {
280 return t;
281 }
282
283 // This formats a value for a failing CHECK_XX statement. Ordinarily,
284 // it uses the definition for operator<<, with a few special cases below.
285 template <typename T>
MakeCheckOpValueString(std::ostream * os,const T & v)286 inline void MakeCheckOpValueString(std::ostream* os, const T& v) {
287 (*os) << v;
288 }
289
290 // Overrides for char types provide readable values for unprintable
291 // characters.
292 template <>
293 void MakeCheckOpValueString(std::ostream* os, const char& v);
294 template <>
295 void MakeCheckOpValueString(std::ostream* os, const signed char& v);
296 template <>
297 void MakeCheckOpValueString(std::ostream* os, const unsigned char& v);
298
299 #if LANG_CXX11
300 // We need an explicit specialization for std::nullptr_t.
301 template <>
302 void MakeCheckOpValueString(std::ostream* os, const std::nullptr_t& p);
303 #endif
304
305 // A container for a string pointer which can be evaluated to a bool -
306 // true iff the pointer is non-NULL.
307 struct CheckOpString {
CheckOpStringCheckOpString308 CheckOpString(string* str) : str_(str) {}
309 // No destructor: if str_ is non-NULL, we're about to LOG(FATAL),
310 // so there's no point in cleaning up str_.
311 operator bool() const { return TF_PREDICT_FALSE(str_ != NULL); }
312 string* str_;
313 };
314
315 // Build the error message string. Specify no inlining for code size.
316 template <typename T1, typename T2>
317 string* MakeCheckOpString(const T1& v1, const T2& v2,
318 const char* exprtext) TF_ATTRIBUTE_NOINLINE;
319
320 // A helper class for formatting "expr (V1 vs. V2)" in a CHECK_XX
321 // statement. See MakeCheckOpString for sample usage. Other
322 // approaches were considered: use of a template method (e.g.,
323 // base::BuildCheckOpString(exprtext, base::Print<T1>, &v1,
324 // base::Print<T2>, &v2), however this approach has complications
325 // related to volatile arguments and function-pointer arguments).
326 class CheckOpMessageBuilder {
327 public:
328 // Inserts "exprtext" and " (" to the stream.
329 explicit CheckOpMessageBuilder(const char* exprtext);
330 // Deletes "stream_".
331 ~CheckOpMessageBuilder();
332 // For inserting the first variable.
ForVar1()333 std::ostream* ForVar1() { return stream_; }
334 // For inserting the second variable (adds an intermediate " vs. ").
335 std::ostream* ForVar2();
336 // Get the result (inserts the closing ")").
337 string* NewString();
338
339 private:
340 std::ostringstream* stream_;
341 };
342
343 template <typename T1, typename T2>
MakeCheckOpString(const T1 & v1,const T2 & v2,const char * exprtext)344 string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext) {
345 CheckOpMessageBuilder comb(exprtext);
346 MakeCheckOpValueString(comb.ForVar1(), v1);
347 MakeCheckOpValueString(comb.ForVar2(), v2);
348 return comb.NewString();
349 }
350
351 // Helper functions for CHECK_OP macro.
352 // The (int, int) specialization works around the issue that the compiler
353 // will not instantiate the template version of the function on values of
354 // unnamed enum type - see comment below.
355 // The (size_t, int) and (int, size_t) specialization are to handle unsigned
356 // comparison errors while still being thorough with the comparison.
357 #define TF_DEFINE_CHECK_OP_IMPL(name, op) \
358 template <typename T1, typename T2> \
359 inline string* name##Impl(const T1& v1, const T2& v2, \
360 const char* exprtext) { \
361 if (TF_PREDICT_TRUE(v1 op v2)) \
362 return NULL; \
363 else \
364 return ::tensorflow::internal::MakeCheckOpString(v1, v2, exprtext); \
365 } \
366 inline string* name##Impl(int v1, int v2, const char* exprtext) { \
367 return name##Impl<int, int>(v1, v2, exprtext); \
368 } \
369 inline string* name##Impl(const size_t v1, const int v2, \
370 const char* exprtext) { \
371 if (TF_PREDICT_FALSE(v2 < 0)) { \
372 return ::tensorflow::internal::MakeCheckOpString(v1, v2, exprtext); \
373 } \
374 return name##Impl<size_t, size_t>(v1, v2, exprtext); \
375 } \
376 inline string* name##Impl(const int v1, const size_t v2, \
377 const char* exprtext) { \
378 if (TF_PREDICT_FALSE(v2 >= std::numeric_limits<int>::max())) { \
379 return ::tensorflow::internal::MakeCheckOpString(v1, v2, exprtext); \
380 } \
381 const size_t uval = (size_t)((unsigned)v2); \
382 return name##Impl<size_t, size_t>(v1, uval, exprtext); \
383 }
384
385 // We use the full name Check_EQ, Check_NE, etc. in case the file including
386 // base/logging.h provides its own #defines for the simpler names EQ, NE, etc.
387 // This happens if, for example, those are used as token names in a
388 // yacc grammar.
389 TF_DEFINE_CHECK_OP_IMPL(Check_EQ,
390 ==) // Compilation error with CHECK_EQ(NULL, x)?
391 TF_DEFINE_CHECK_OP_IMPL(Check_NE, !=) // Use CHECK(x == NULL) instead.
392 TF_DEFINE_CHECK_OP_IMPL(Check_LE, <=)
393 TF_DEFINE_CHECK_OP_IMPL(Check_LT, <)
394 TF_DEFINE_CHECK_OP_IMPL(Check_GE, >=)
395 TF_DEFINE_CHECK_OP_IMPL(Check_GT, >)
396 #undef TF_DEFINE_CHECK_OP_IMPL
397
398 // In optimized mode, use CheckOpString to hint to compiler that
399 // the while condition is unlikely.
400 #define CHECK_OP_LOG(name, op, val1, val2) \
401 while (::tensorflow::internal::CheckOpString _result = \
402 ::tensorflow::internal::name##Impl( \
403 ::tensorflow::internal::GetReferenceableValue(val1), \
404 ::tensorflow::internal::GetReferenceableValue(val2), \
405 #val1 " " #op " " #val2)) \
406 ::tensorflow::internal::LogMessageFatal(__FILE__, __LINE__) << *(_result.str_)
407
408 #define CHECK_OP(name, op, val1, val2) CHECK_OP_LOG(name, op, val1, val2)
409
410 // CHECK_EQ/NE/...
411 #define CHECK_EQ(val1, val2) CHECK_OP(Check_EQ, ==, val1, val2)
412 #define CHECK_NE(val1, val2) CHECK_OP(Check_NE, !=, val1, val2)
413 #define CHECK_LE(val1, val2) CHECK_OP(Check_LE, <=, val1, val2)
414 #define CHECK_LT(val1, val2) CHECK_OP(Check_LT, <, val1, val2)
415 #define CHECK_GE(val1, val2) CHECK_OP(Check_GE, >=, val1, val2)
416 #define CHECK_GT(val1, val2) CHECK_OP(Check_GT, >, val1, val2)
417 #define CHECK_NOTNULL(val) \
418 ::tensorflow::internal::CheckNotNull(__FILE__, __LINE__, \
419 "'" #val "' Must be non NULL", (val))
420
421 #ifndef NDEBUG
422 // DCHECK_EQ/NE/...
423 #define DCHECK(condition) CHECK(condition)
424 #define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2)
425 #define DCHECK_NE(val1, val2) CHECK_NE(val1, val2)
426 #define DCHECK_LE(val1, val2) CHECK_LE(val1, val2)
427 #define DCHECK_LT(val1, val2) CHECK_LT(val1, val2)
428 #define DCHECK_GE(val1, val2) CHECK_GE(val1, val2)
429 #define DCHECK_GT(val1, val2) CHECK_GT(val1, val2)
430
431 #else
432
433 #define DCHECK(condition) \
434 while (false && (condition)) LOG(FATAL)
435
436 // NDEBUG is defined, so DCHECK_EQ(x, y) and so on do nothing.
437 // However, we still want the compiler to parse x and y, because
438 // we don't want to lose potentially useful errors and warnings.
439 // _DCHECK_NOP is a helper, and should not be used outside of this file.
440 #define _TF_DCHECK_NOP(x, y) \
441 while (false && ((void)(x), (void)(y), 0)) LOG(FATAL)
442
443 #define DCHECK_EQ(x, y) _TF_DCHECK_NOP(x, y)
444 #define DCHECK_NE(x, y) _TF_DCHECK_NOP(x, y)
445 #define DCHECK_LE(x, y) _TF_DCHECK_NOP(x, y)
446 #define DCHECK_LT(x, y) _TF_DCHECK_NOP(x, y)
447 #define DCHECK_GE(x, y) _TF_DCHECK_NOP(x, y)
448 #define DCHECK_GT(x, y) _TF_DCHECK_NOP(x, y)
449
450 #endif
451
452 // These are for when you don't want a CHECK failure to print a verbose
453 // stack trace. The implementation of CHECK* in this file already doesn't.
454 #define QCHECK(condition) CHECK(condition)
455 #define QCHECK_EQ(x, y) CHECK_EQ(x, y)
456 #define QCHECK_NE(x, y) CHECK_NE(x, y)
457 #define QCHECK_LE(x, y) CHECK_LE(x, y)
458 #define QCHECK_LT(x, y) CHECK_LT(x, y)
459 #define QCHECK_GE(x, y) CHECK_GE(x, y)
460 #define QCHECK_GT(x, y) CHECK_GT(x, y)
461
462 template <typename T>
CheckNotNull(const char * file,int line,const char * exprtext,T && t)463 T&& CheckNotNull(const char* file, int line, const char* exprtext, T&& t) {
464 if (t == nullptr) {
465 LogMessageFatal(file, line) << string(exprtext);
466 }
467 return std::forward<T>(t);
468 }
469
470 int64 MinLogLevelFromEnv();
471
472 int64 MinVLogLevelFromEnv();
473
474 } // namespace internal
475
476 #ifdef TF_ANDROID_ENABLE_LOGSINK
477 // LogSink support adapted from //base/logging.h
478 //
479 // `LogSink` is an interface which can be extended to intercept and process
480 // all log messages. LogSink implementations must be thread-safe. A single
481 // instance will be called from whichever thread is performing a logging
482 // operation.
483 class TFLogEntry {
AsAbslLogSeverity(int severity)484 static absl::LogSeverity AsAbslLogSeverity(int severity) {
485 return static_cast<absl::LogSeverity>(severity);
486 }
487
488 public:
TFLogEntry(int severity,absl::string_view log_line)489 explicit TFLogEntry(int severity, absl::string_view log_line)
490 : severity_(AsAbslLogSeverity(severity)), log_line_(log_line) {}
491
log_severity()492 absl::LogSeverity log_severity() const { return severity_; }
ToString()493 std::string ToString() const { return std::string(log_line_); }
494
495 private:
496 const absl::LogSeverity severity_;
497 const absl::string_view log_line_;
498 };
499
500 class TFLogSink {
501 public:
502 virtual ~TFLogSink() = default;
503
504 // `Send` is called synchronously during the log statement. The logging
505 // module guarantees not to call `Send` concurrently on the same log sink.
506 // Implementations should be careful not to call`LOG` or `CHECK` or take
507 // any locks that might be held by the `LOG` caller, to avoid deadlock.
508 //
509 // `e` is guaranteed to remain valid until the subsequent call to
510 // `WaitTillSent` completes, so implementations may store a pointer to or
511 // copy of `e` (e.g. in a thread local variable) for use in `WaitTillSent`.
512 virtual void Send(const TFLogEntry& entry) = 0;
513
514 // `WaitTillSent` blocks the calling thread (the thread that generated a log
515 // message) until the sink has finished processing the log message.
516 // `WaitTillSent` is called once per log message, following the call to
517 // `Send`. This may be useful when log messages are buffered or processed
518 // asynchronously by an expensive log sink.
519 // The default implementation returns immediately. Like `Send`,
520 // implementations should be careful not to call `LOG` or `CHECK or take any
521 // locks that might be held by the `LOG` caller, to avoid deadlock.
WaitTillSent()522 virtual void WaitTillSent() {}
523 };
524
525 // Add or remove a `LogSink` as a consumer of logging data. Thread-safe.
526 void TFAddLogSink(TFLogSink* sink);
527 void TFRemoveLogSink(TFLogSink* sink);
528 #endif // TF_ANDROID_ENABLE_LOGSINK
529 } // namespace tensorflow
530
531 #endif // TENSORFLOW_CORE_PLATFORM_DEFAULT_LOGGING_H_
532