mirror of
https://github.com/wassname/ray.git
synced 2026-09-11 12:43:20 +08:00
Hotfix for glog PR (#2734)
This commit is contained in:
committed by
Robert Nishihara
parent
d16b6f6a32
commit
697bfb14db
@@ -114,10 +114,11 @@ void RayLog::ShutDownRayLog() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
RayLog::RayLog(const char *file_name, int line_number, int severity) {
|
RayLog::RayLog(const char *file_name, int line_number, int severity)
|
||||||
|
// glog does not have DEBUG level, we can handle it here.
|
||||||
|
: is_enabled_(severity >= severity_threshold_) {
|
||||||
#ifdef RAY_USE_GLOG
|
#ifdef RAY_USE_GLOG
|
||||||
// glog does not have DEBUG level, we can handle it here.
|
if (is_enabled_) {
|
||||||
if (severity >= severity_threshold_) {
|
|
||||||
logging_provider_.reset(
|
logging_provider_.reset(
|
||||||
new google::LogMessage(file_name, line_number, GetMappedSeverity(severity)));
|
new google::LogMessage(file_name, line_number, GetMappedSeverity(severity)));
|
||||||
}
|
}
|
||||||
@@ -129,12 +130,16 @@ RayLog::RayLog(const char *file_name, int line_number, int severity) {
|
|||||||
|
|
||||||
std::ostream &RayLog::Stream() {
|
std::ostream &RayLog::Stream() {
|
||||||
#ifdef RAY_USE_GLOG
|
#ifdef RAY_USE_GLOG
|
||||||
|
// Before calling this function, user should check IsEnabled.
|
||||||
|
// When IsEnabled == false, logging_provider_ will be empty.
|
||||||
return logging_provider_->stream();
|
return logging_provider_->stream();
|
||||||
#else
|
#else
|
||||||
return logging_provider_->Stream();
|
return logging_provider_->Stream();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RayLog::IsEnabled() const { return is_enabled_; }
|
||||||
|
|
||||||
RayLog::~RayLog() { logging_provider_.reset(); }
|
RayLog::~RayLog() { logging_provider_.reset(); }
|
||||||
|
|
||||||
} // namespace ray
|
} // namespace ray
|
||||||
|
|||||||
+20
-12
@@ -65,28 +65,32 @@ class RayLogBase {
|
|||||||
public:
|
public:
|
||||||
virtual ~RayLogBase(){};
|
virtual ~RayLogBase(){};
|
||||||
|
|
||||||
|
virtual bool IsEnabled() const { return false; };
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
RayLogBase &operator<<(const T &t) {
|
RayLogBase &operator<<(const T &t) {
|
||||||
RAY_IGNORE_EXPR(t);
|
if (IsEnabled()) {
|
||||||
|
Stream() << t;
|
||||||
|
} else {
|
||||||
|
RAY_IGNORE_EXPR(t);
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual std::ostream &Stream() { return std::cerr; };
|
||||||
};
|
};
|
||||||
|
|
||||||
class RayLog : public RayLogBase {
|
class RayLog : public RayLogBase {
|
||||||
public:
|
public:
|
||||||
RayLog(const char *file_name, int line_number, int severity);
|
RayLog(const char *file_name, int line_number, int severity);
|
||||||
|
|
||||||
virtual ~RayLog();
|
virtual ~RayLog();
|
||||||
|
|
||||||
template <typename T>
|
/// Return whether or not logging is enabled.
|
||||||
RayLogBase &operator<<(const T &t) {
|
///
|
||||||
if (logging_provider_ == nullptr) {
|
/// \return True if logging is enabled and false otherwise.
|
||||||
// This means the logging level is lower than the threshold.
|
virtual bool IsEnabled() const;
|
||||||
RAY_IGNORE_EXPR(t);
|
|
||||||
} else {
|
|
||||||
this->Stream() << t;
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The init function of ray log for a program which should be called only once.
|
// The init function of ray log for a program which should be called only once.
|
||||||
// If logDir is empty, the log won't output to file.
|
// If logDir is empty, the log won't output to file.
|
||||||
@@ -96,9 +100,13 @@ class RayLog : public RayLogBase {
|
|||||||
static void ShutDownRayLog();
|
static void ShutDownRayLog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ostream &Stream();
|
|
||||||
std::unique_ptr<LoggingProvider> logging_provider_;
|
std::unique_ptr<LoggingProvider> logging_provider_;
|
||||||
|
/// True if log messages should be logged and false if they should be ignored.
|
||||||
|
bool is_enabled_;
|
||||||
static int severity_threshold_;
|
static int severity_threshold_;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual std::ostream &Stream();
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class make RAY_CHECK compilation pass to change the << operator to void.
|
// This class make RAY_CHECK compilation pass to change the << operator to void.
|
||||||
|
|||||||
@@ -18,11 +18,17 @@ int64_t current_time_ms() {
|
|||||||
// This file just print some information using the logging macro.
|
// This file just print some information using the logging macro.
|
||||||
|
|
||||||
void PrintLog() {
|
void PrintLog() {
|
||||||
RAY_LOG(DEBUG) << "This is the DEBUG message";
|
RAY_LOG(DEBUG) << "This is the"
|
||||||
RAY_LOG(INFO) << "This is the INFO message";
|
<< " DEBUG"
|
||||||
RAY_LOG(WARNING) << "This is the WARNING message";
|
<< " message";
|
||||||
RAY_LOG(ERROR) << "This is the ERROR message";
|
RAY_LOG(INFO) << "This is the"
|
||||||
RAY_CHECK(true) << "This is a RAY_CHECK message but it won't show up";
|
<< " INFO message";
|
||||||
|
RAY_LOG(WARNING) << "This is the"
|
||||||
|
<< " WARNING message";
|
||||||
|
RAY_LOG(ERROR) << "This is the"
|
||||||
|
<< " ERROR message";
|
||||||
|
RAY_CHECK(true) << "This is a RAY_CHECK"
|
||||||
|
<< " message but it won't show up";
|
||||||
// The following 2 lines should not run since it will cause program failure.
|
// The following 2 lines should not run since it will cause program failure.
|
||||||
// RAY_LOG(FATAL) << "This is the FATAL message";
|
// RAY_LOG(FATAL) << "This is the FATAL message";
|
||||||
// RAY_CHECK(false) << "This is a RAY_CHECK message but it won't show up";
|
// RAY_CHECK(false) << "This is a RAY_CHECK message but it won't show up";
|
||||||
@@ -47,7 +53,8 @@ TEST(LogPerfTest, PerfTest) {
|
|||||||
|
|
||||||
int64_t start_time = current_time_ms();
|
int64_t start_time = current_time_ms();
|
||||||
for (int i = 0; i < rounds; ++i) {
|
for (int i = 0; i < rounds; ++i) {
|
||||||
RAY_LOG(DEBUG) << "This is the RAY_DEBUG message";
|
RAY_LOG(DEBUG) << "This is the "
|
||||||
|
<< "RAY_DEBUG message";
|
||||||
}
|
}
|
||||||
int64_t elapsed = current_time_ms() - start_time;
|
int64_t elapsed = current_time_ms() - start_time;
|
||||||
std::cout << "Testing DEBUG log for " << rounds << " rounds takes " << elapsed << " ms."
|
std::cout << "Testing DEBUG log for " << rounds << " rounds takes " << elapsed << " ms."
|
||||||
@@ -55,7 +62,8 @@ TEST(LogPerfTest, PerfTest) {
|
|||||||
|
|
||||||
start_time = current_time_ms();
|
start_time = current_time_ms();
|
||||||
for (int i = 0; i < rounds; ++i) {
|
for (int i = 0; i < rounds; ++i) {
|
||||||
RAY_LOG(ERROR) << "This is the RAY_ERROR message";
|
RAY_LOG(ERROR) << "This is the "
|
||||||
|
<< "RAY_ERROR message";
|
||||||
}
|
}
|
||||||
elapsed = current_time_ms() - start_time;
|
elapsed = current_time_ms() - start_time;
|
||||||
std::cout << "Testing RAY_ERROR log for " << rounds << " rounds takes " << elapsed
|
std::cout << "Testing RAY_ERROR log for " << rounds << " rounds takes " << elapsed
|
||||||
@@ -63,7 +71,8 @@ TEST(LogPerfTest, PerfTest) {
|
|||||||
|
|
||||||
start_time = current_time_ms();
|
start_time = current_time_ms();
|
||||||
for (int i = 0; i < rounds; ++i) {
|
for (int i = 0; i < rounds; ++i) {
|
||||||
RAY_CHECK(i >= 0) << "This is a RAY_CHECK message but it won't show up";
|
RAY_CHECK(i >= 0) << "This is a RAY_CHECK "
|
||||||
|
<< "message but it won't show up";
|
||||||
}
|
}
|
||||||
elapsed = current_time_ms() - start_time;
|
elapsed = current_time_ms() - start_time;
|
||||||
std::cout << "Testing RAY_CHECK(true) for " << rounds << " rounds takes " << elapsed
|
std::cout << "Testing RAY_CHECK(true) for " << rounds << " rounds takes " << elapsed
|
||||||
|
|||||||
Reference in New Issue
Block a user