1
- #include " caffe2/core/logging .h"
2
- #include " caffe2/core/flags .h"
1
+ #include " c10/util/Logging .h"
2
+ #include " c10/util/Flags .h"
3
3
4
4
#include < algorithm>
5
5
#include < cstring>
@@ -14,7 +14,7 @@ C10_DEFINE_bool(
14
14
" If set true, when CAFFE_ENFORCE is not met, abort instead "
15
15
" of throwing an exception." );
16
16
17
- namespace caffe2 {
17
+ namespace c10 {
18
18
namespace enforce_detail {
19
19
/* implicit */ EnforceFailMessage::EnforceFailMessage(std::string&& msg) {
20
20
msg_ = new std::string (std::move (msg));
@@ -45,9 +45,9 @@ void ThrowEnforceNotMet(
45
45
throw e;
46
46
}
47
47
48
- } // namespace caffe2
48
+ } // namespace c10
49
49
50
- #ifdef C10_USE_GFLAGS
50
+ #if defined( C10_USE_GFLAGS) && defined(C10_USE_GLOG)
51
51
// When GLOG depends on GFLAGS, these variables are being defined in GLOG
52
52
// directly via the GFLAGS definition, so we will use DECLARE_* to declare
53
53
// them, and use them in Caffe2.
@@ -57,25 +57,28 @@ DECLARE_int32(minloglevel);
57
57
DECLARE_int32 (v);
58
58
// GLOG's logtostderr value
59
59
DECLARE_bool (logtostderr);
60
- #elif !CAFFE2_MOBILE && !__APPLE__ && !defined(_WIN32)
61
- // Declare our own versions of the above flags so we don't error out
62
- // when they are passed into Caffe2.
63
- C10_DEFINE_int (minloglevel, 0 , " Equivalent to glog minloglevel" );
64
- C10_DEFINE_int (v, 0 , " Equivalent to glog verbose" );
60
+ #endif // defined(C10_USE_GFLAGS) && defined(C10_USE_GLOG)
61
+
62
+ #if !defined(C10_USE_GLOG)
63
+ // This backward compatibility flags are in order to deal with cases where
64
+ // Caffe2 are not built with glog, but some init flags still pass in these
65
+ // flags. They may go away in the future.
66
+ C10_DEFINE_int32 (minloglevel, 0 , " Equivalent to glog minloglevel" );
67
+ C10_DEFINE_int32 (v, 0 , " Equivalent to glog verbose" );
65
68
C10_DEFINE_bool (logtostderr, false , " Equivalent to glog logtostderr" );
66
- #endif // C10_USE_GFLAGS
69
+ #endif // !defined(c10_USE_GLOG)
67
70
68
- #ifdef CAFFE2_USE_GOOGLE_GLOG
71
+ #ifdef C10_USE_GLOG
69
72
70
73
// Provide easy access to the above variables, regardless whether GLOG is
71
74
// dependent on GFLAGS or not. Note that the namespace (fLI, fLB) is actually
72
75
// consistent between GLOG and GFLAGS, so we can do the below declaration
73
76
// consistently.
74
- namespace caffe2 {
77
+ namespace c10 {
78
+ using fLB ::FLAGS_logtostderr;
75
79
using fLI ::FLAGS_minloglevel;
76
80
using fLI ::FLAGS_v;
77
- using fLB ::FLAGS_logtostderr;
78
- } // namespace caffe2
81
+ } // namespace c10
79
82
80
83
C10_DEFINE_int (
81
84
caffe2_log_level,
@@ -89,21 +92,21 @@ C10_DEFINE_int(
89
92
namespace google {
90
93
namespace glog_internal_namespace_ {
91
94
bool IsGoogleLoggingInitialized ();
92
- } // namespace glog_internal_namespace_
93
- } // namespace google
95
+ } // namespace glog_internal_namespace_
96
+ } // namespace google
94
97
95
-
96
- namespace caffe2 {
98
+ namespace c10 {
97
99
bool InitCaffeLogging (int * argc, char ** argv) {
98
- if (*argc == 0 ) return true ;
100
+ if (*argc == 0 )
101
+ return true ;
99
102
#if !defined(_MSC_VER)
100
103
// This trick can only be used on UNIX platforms
101
104
if (!::google::glog_internal_namespace_::IsGoogleLoggingInitialized ())
102
105
#endif
103
106
{
104
107
::google::InitGoogleLogging (argv[0 ]);
105
108
#if !defined(_MSC_VER)
106
- // This is never defined on Windows
109
+ // This is never defined on Windows
107
110
::google::InstallFailureSignalHandler ();
108
111
#endif
109
112
}
@@ -129,9 +132,9 @@ void ShowLogInfoToStderr() {
129
132
FLAGS_logtostderr = 1 ;
130
133
FLAGS_minloglevel = std::min (FLAGS_minloglevel, google::GLOG_INFO);
131
134
}
132
- } // namespace caffe2
135
+ } // namespace c10
133
136
134
- #else // !CAFFE2_USE_GOOGLE_GLOG
137
+ #else // !C10_USE_GLOG
135
138
136
139
#ifdef ANDROID
137
140
#include < android/log.h>
@@ -142,11 +145,12 @@ C10_DEFINE_int(
142
145
ERROR,
143
146
" The minimum log level that caffe2 will output." );
144
147
145
- namespace caffe2 {
148
+ namespace c10 {
146
149
bool InitCaffeLogging (int * argc, char ** argv) {
147
150
// When doing InitCaffeLogging, we will assume that caffe's flag paser has
148
151
// already finished.
149
- if (*argc == 0 ) return true ;
152
+ if (*argc == 0 )
153
+ return true ;
150
154
if (!c10::CommandLineFlagsHasBeenParsed ()) {
151
155
std::cerr << " InitCaffeLogging() has to be called after "
152
156
" c10::ParseCommandLineFlags. Modify your program to make sure "
@@ -162,24 +166,23 @@ bool InitCaffeLogging(int* argc, char** argv) {
162
166
return true ;
163
167
}
164
168
165
- void UpdateLoggingLevelsFromFlags () {
166
- }
169
+ void UpdateLoggingLevelsFromFlags () {}
167
170
168
171
void ShowLogInfoToStderr () {
169
172
FLAGS_caffe2_log_level = INFO;
170
173
}
171
174
172
- MessageLogger::MessageLogger (const char * file, int line, int severity)
173
- : severity_(severity) {
175
+ MessageLogger::MessageLogger (const char * file, int line, int severity)
176
+ : severity_(severity) {
174
177
if (severity_ < FLAGS_caffe2_log_level) {
175
178
// Nothing needs to be logged.
176
179
return ;
177
180
}
178
181
#ifdef ANDROID
179
182
tag_ = " native" ;
180
- #else // !ANDROID
183
+ #else // !ANDROID
181
184
tag_ = " " ;
182
- #endif // ANDROID
185
+ #endif // ANDROID
183
186
/*
184
187
time_t rawtime;
185
188
struct tm * timeinfo;
@@ -210,12 +213,12 @@ MessageLogger::~MessageLogger() {
210
213
stream_ << " \n " ;
211
214
#ifdef ANDROID
212
215
static const int android_log_levels[] = {
213
- ANDROID_LOG_FATAL, // LOG_FATAL
214
- ANDROID_LOG_ERROR, // LOG_ERROR
215
- ANDROID_LOG_WARN, // LOG_WARNING
216
- ANDROID_LOG_INFO, // LOG_INFO
217
- ANDROID_LOG_DEBUG, // VLOG(1)
218
- ANDROID_LOG_VERBOSE, // VLOG(2) .. VLOG(N)
216
+ ANDROID_LOG_FATAL, // LOG_FATAL
217
+ ANDROID_LOG_ERROR, // LOG_ERROR
218
+ ANDROID_LOG_WARN, // LOG_WARNING
219
+ ANDROID_LOG_INFO, // LOG_INFO
220
+ ANDROID_LOG_DEBUG, // VLOG(1)
221
+ ANDROID_LOG_VERBOSE, // VLOG(2) .. VLOG(N)
219
222
};
220
223
int android_level_index = FATAL - std::min (FATAL, severity_);
221
224
int level = android_log_levels[std::min (android_level_index, 5 )];
@@ -225,7 +228,7 @@ MessageLogger::~MessageLogger() {
225
228
if (severity_ == FATAL) {
226
229
__android_log_print (ANDROID_LOG_FATAL, tag_, " terminating.\n " );
227
230
}
228
- #else // !ANDROID
231
+ #else // !ANDROID
229
232
if (severity_ >= FLAGS_caffe2_log_level) {
230
233
// If not building on Android, log all output to std::cerr.
231
234
std::cerr << stream_.str ();
@@ -236,12 +239,12 @@ MessageLogger::~MessageLogger() {
236
239
std::cerr << std::flush;
237
240
}
238
241
}
239
- #endif // ANDROID
242
+ #endif // ANDROID
240
243
if (severity_ == FATAL) {
241
244
DealWithFatal ();
242
245
}
243
246
}
244
247
245
- } // namespace caffe2
248
+ } // namespace c10
246
249
247
- #endif // !CAFFE2_USE_GOOGLE_GLOG
250
+ #endif // !C10_USE_GLOG
0 commit comments