Skip to content

Commit 47a3c25

Browse files
authored
Convert to C API logging (#1202)
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
1 parent f97d250 commit 47a3c25

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

tensorflow_io/core/plugins/az/az_file_system.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ limitations under the License.
3131
#include "storage_account.h"
3232
#include "storage_credential.h"
3333
#include "storage_errno.h"
34+
// TODO: Restore logging.h
35+
#define TF_Log(...)
36+
#define TF_VLog(...)
37+
// #include "tensorflow/c/logging.h"
38+
// TODO: Restore logging.h
39+
#include "tensorflow/c/tf_status.h"
3440
#include "tensorflow_io/core/plugins/file_system_plugins.h"
3541

3642
namespace tensorflow {
@@ -191,21 +197,20 @@ std::shared_ptr<azure::storage_lite::storage_credential> get_credential(
191197
}
192198
}
193199

194-
// TODO: Enable logging
195200
azure::storage_lite::blob_client_wrapper CreateAzBlobClientWrapper(
196201
const std::string& account) {
197202
azure::storage_lite::logger::set_logger(
198203
[](azure::storage_lite::log_level level, const std::string& log_msg) {
199204
switch (level) {
200205
case azure::storage_lite::log_level::info:
201-
// _TF_LOG_INFO << log_msg;
206+
TF_Log(TF_INFO, log_msg.c_str());
202207
break;
203208
case azure::storage_lite::log_level::error:
204209
case azure::storage_lite::log_level::critical:
205-
// _TF_LOG_ERROR << log_msg;
210+
TF_Log(TF_ERROR, log_msg.c_str());
206211
break;
207212
case azure::storage_lite::log_level::warn:
208-
// _TF_LOG_WARNING << log_msg;
213+
TF_Log(TF_WARNING, log_msg.c_str());
209214
break;
210215
case azure::storage_lite::log_level::trace:
211216
case azure::storage_lite::log_level::debug:

tensorflow_io/core/plugins/hdfs/hadoop_filesystem.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ limitations under the License.
3131
#include "absl/strings/str_cat.h"
3232
#include "absl/synchronization/mutex.h"
3333
#include "hdfs/hdfs.h"
34-
#include "tensorflow/c/tf_status.h"
35-
#include "tensorflow_io/core/plugins/file_system_plugins.h"
3634
// TODO: Restore logging.h
3735
#define TF_Log(...)
3836
#define TF_VLog(...)
3937
// #include "tensorflow/c/logging.h"
4038
// TODO: Restore logging.h
39+
#include "tensorflow/c/tf_status.h"
40+
#include "tensorflow_io/core/plugins/file_system_plugins.h"
4141

4242
namespace tensorflow {
4343
namespace io {

tensorflow_io/core/plugins/http/http_file_system.cc

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ limitations under the License.
2222
#include "absl/strings/ascii.h"
2323
#include "absl/strings/str_cat.h"
2424
#include "absl/synchronization/mutex.h"
25+
// TODO: Restore logging.h
26+
#define TF_Log(...)
27+
#define TF_VLog(...)
28+
// #include "tensorflow/c/logging.h"
29+
// TODO: Restore logging.h
30+
#include "tensorflow/c/tf_status.h"
2531
#include "tensorflow_io/core/plugins/file_system_plugins.h"
2632

2733
namespace tensorflow {
@@ -473,20 +479,21 @@ class CurlHttpRequest {
473479
const auto starttransfer_time_status = curl_easy_getinfo(
474480
that->curl_, CURLINFO_STARTTRANSFER_TIME, &starttransfer_time);
475481

476-
// TODO: Use C API from TensorFlow for Logging.
477-
// LOG(ERROR) << "The transmission of request " << this_object
478-
// << " (URI: " << that->uri_ << ") has been stuck at "
479-
// << current_progress << " of " << dltotal + ultotal
480-
// << " bytes for " << now - that->last_progress_timestamp_
481-
// << " seconds and will be aborted. CURL timing information: "
482-
// << "lookup time: " << lookup_time << " ("
483-
// << curl_easy_strerror(lookup_time_status)
484-
// << "), connect time: " << connect_time << " ("
485-
// << curl_easy_strerror(connect_time_status)
486-
// << "), pre-transfer time: " << pretransfer_time << " ("
487-
// << curl_easy_strerror(pretransfer_time_status)
488-
// << "), start-transfer time: " << starttransfer_time << " ("
489-
// << curl_easy_strerror(starttransfer_time_status) << ")";
482+
std::string error_message = absl::StrCat(
483+
"The transmission of request ", (int64_t)(this_object),
484+
" (URI: ", that->uri_, ") has been stuck at ", current_progress,
485+
" of ", dltotal + ultotal, " bytes for ",
486+
now - that->last_progress_timestamp_,
487+
" seconds and will be aborted. CURL timing information: ",
488+
"lookup time: ", lookup_time, " (",
489+
curl_easy_strerror(lookup_time_status),
490+
"), connect time: ", connect_time, " (",
491+
curl_easy_strerror(connect_time_status),
492+
"), pre-transfer time: ", pretransfer_time, " (",
493+
curl_easy_strerror(pretransfer_time_status),
494+
"), start-transfer time: ", starttransfer_time, " (",
495+
curl_easy_strerror(starttransfer_time_status), ")");
496+
TF_Log(TF_ERROR, error_message.c_str());
490497
return 1; // Will abort the request.
491498
}
492499
// No progress was made since the last call, but we should wait a bit

0 commit comments

Comments
 (0)