Skip to content

Commit

Permalink
[core] Fix default logging rotation size (#49726)
Browse files Browse the repository at this point in the history
Signed-off-by: dentiny <dentinyhao@gmail.com>
  • Loading branch information
dentiny authored Jan 9, 2025
1 parent 57d09ba commit ea4e315
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
6 changes: 2 additions & 4 deletions src/ray/util/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>::max();
}

/*static*/ size_t RayLog::GetRayLogRotationBackupCountOrDefault() {
Expand All @@ -330,7 +328,7 @@ void RayLog::InitLogFormat() {
return file_num;
}
}
return kDefaultLogRotationFileNum;
return 1;
}

/*static*/ std::string RayLog::GetLogFilepathFromDirectory(const std::string &log_dir,
Expand Down
25 changes: 12 additions & 13 deletions src/ray/util/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ enum class RayLogLevel {
/// The second argument: log content.
using FatalLogCallback = std::function<void(const std::string &, const std::string &)>;

// 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);
Expand Down Expand Up @@ -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<size_t>::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.
Expand Down Expand Up @@ -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<size_t>::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_;

Expand Down

0 comments on commit ea4e315

Please sign in to comment.