From ea4e3152a3fdc6c097a804258d1338066b56ef63 Mon Sep 17 00:00:00 2001 From: dentiny Date: Wed, 8 Jan 2025 21:22:09 -0800 Subject: [PATCH] [core] Fix default logging rotation size (#49726) Signed-off-by: dentiny --- src/ray/util/logging.cc | 6 ++---- src/ray/util/logging.h | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/ray/util/logging.cc b/src/ray/util/logging.cc index eb9173ada621..3e4027775143 100644 --- a/src/ray/util/logging.cc +++ b/src/ray/util/logging.cc @@ -314,12 +314,10 @@ void RayLog::InitLogFormat() { ray_rotation_max_bytes != nullptr) { size_t max_size = 0; if (absl::SimpleAtoi(ray_rotation_max_bytes, &max_size) && max_size > 0) { - // 0 means no log rotation in python, but not in spdlog. We just use the default - // value here. return max_size; } } - return kDefaultLogRotationMaxSize; + return std::numeric_limits::max(); } /*static*/ size_t RayLog::GetRayLogRotationBackupCountOrDefault() { @@ -330,7 +328,7 @@ void RayLog::InitLogFormat() { return file_num; } } - return kDefaultLogRotationFileNum; + return 1; } /*static*/ std::string RayLog::GetLogFilepathFromDirectory(const std::string &log_dir, diff --git a/src/ray/util/logging.h b/src/ray/util/logging.h index 34a9cbe6e2ad..8b6401f99be2 100644 --- a/src/ray/util/logging.h +++ b/src/ray/util/logging.h @@ -243,10 +243,6 @@ enum class RayLogLevel { /// The second argument: log content. using FatalLogCallback = std::function; -// Default configs for ray log. -inline constexpr size_t kDefaultLogRotationMaxSize = 1ULL << 29; -inline constexpr size_t kDefaultLogRotationFileNum = 10; - class RayLog { public: RayLog(const char *file_name, int line_number, RayLogLevel severity); @@ -279,22 +275,25 @@ class RayLog { /// /// \param log_rotation_max_size max bytes for of log rotation. /// \param log_rotation_file_num max number of rotating log files. - static void StartRayLog(const std::string &app_name, - RayLogLevel severity_threshold = RayLogLevel::INFO, - const std::string &log_filepath = "", - size_t log_rotation_max_size = kDefaultLogRotationMaxSize, - size_t log_rotation_file_num = kDefaultLogRotationFileNum); + static void StartRayLog( + const std::string &app_name, + RayLogLevel severity_threshold = RayLogLevel::INFO, + const std::string &log_filepath = "", + size_t log_rotation_max_size = std::numeric_limits::max(), + size_t log_rotation_file_num = 1); /// The shutdown function of ray log which should be used with StartRayLog as a pair. /// If `StartRayLog` wasn't called before, it will be no-op. static void ShutDownRayLog(); /// Get max bytes value from env variable. - /// Return default value `kDefaultLogRotationMaxSize` if env not set or parse failure. + /// Return default value, which indicates no rotation, if env not set, parse failure or + /// value 0. static size_t GetRayLogRotationMaxBytesOrDefault(); /// Get log rotation backup count. - /// Return default value `kDefaultLogRotationFileNum` if env not set or parse failure. + /// Return default value, which indicates no rotation, if env not set, parse failure or + /// value 0. static size_t GetRayLogRotationBackupCountOrDefault(); /// Uninstall the signal actions installed by InstallFailureSignalHandler. @@ -414,9 +413,9 @@ class RayLog { // Log format pattern. static std::string log_format_pattern_; // Log rotation file size limitation. - inline static size_t log_rotation_max_size_ = kDefaultLogRotationMaxSize; + inline static size_t log_rotation_max_size_ = std::numeric_limits::max(); // Log rotation file number. - inline static size_t log_rotation_file_num_ = kDefaultLogRotationFileNum; + inline static size_t log_rotation_file_num_ = 1; // Ray default logger name. static std::string logger_name_;