diff --git a/python/ray/includes/global_state_accessor.pxd b/python/ray/includes/global_state_accessor.pxd index a38db9fb0403..505f345c97ce 100644 --- a/python/ray/includes/global_state_accessor.pxd +++ b/python/ray/includes/global_state_accessor.pxd @@ -83,7 +83,8 @@ cdef extern from * namespace "ray::gcs" nogil: ray::RayLog::ShutDownRayLog, "ray_init", ray::RayLogLevel::WARNING, - "" /* log_dir */); + "" /* log_dir */, + "" /*log_file */); RedisClientOptions options(host, port, password, use_ssl); diff --git a/src/ray/common/test/ray_syncer_test.cc b/src/ray/common/test/ray_syncer_test.cc index cc80af47018d..3495ceaca50e 100644 --- a/src/ray/common/test/ray_syncer_test.cc +++ b/src/ray/common/test/ray_syncer_test.cc @@ -937,7 +937,8 @@ int main(int argc, char **argv) { ray::RayLog::ShutDownRayLog, argv[0], ray::RayLogLevel::INFO, - /*log_dir=*/""); + /*log_dir=*/"", + /*log_file=*/""); ray::RayLog::InstallFailureSignalHandler(argv[0]); ray::RayLog::InstallTerminateHandler(); diff --git a/src/ray/core_worker/test/actor_creator_test.cc b/src/ray/core_worker/test/actor_creator_test.cc index f23edd8be8c7..b254605ea071 100644 --- a/src/ray/core_worker/test/actor_creator_test.cc +++ b/src/ray/core_worker/test/actor_creator_test.cc @@ -90,7 +90,8 @@ int main(int argc, char **argv) { ray::RayLog::ShutDownRayLog, argv[0], ray::RayLogLevel::INFO, - /*log_dir=*/""); + /*log_dir=*/"", + /*log_file=*/""); ray::RayLog::InstallFailureSignalHandler(argv[0]); return RUN_ALL_TESTS(); } diff --git a/src/ray/core_worker/test/direct_actor_transport_test.cc b/src/ray/core_worker/test/direct_actor_transport_test.cc index b6b5d2278f03..26ee3ed53ee4 100644 --- a/src/ray/core_worker/test/direct_actor_transport_test.cc +++ b/src/ray/core_worker/test/direct_actor_transport_test.cc @@ -980,7 +980,8 @@ int main(int argc, char **argv) { ray::RayLog::ShutDownRayLog, argv[0], ray::RayLogLevel::INFO, - /*log_dir=*/""); + /*log_dir=*/"", + /*log_file=*/""); ray::RayLog::InstallFailureSignalHandler(argv[0]); return RUN_ALL_TESTS(); } diff --git a/src/ray/gcs/gcs_client/test/gcs_client_reconnection_test.cc b/src/ray/gcs/gcs_client/test/gcs_client_reconnection_test.cc index 2e003ec39977..a78e74efe3f6 100644 --- a/src/ray/gcs/gcs_client/test/gcs_client_reconnection_test.cc +++ b/src/ray/gcs/gcs_client/test/gcs_client_reconnection_test.cc @@ -382,7 +382,8 @@ int main(int argc, char **argv) { ray::RayLog::ShutDownRayLog, argv[0], ray::RayLogLevel::INFO, - /*log_dir=*/""); + /*log_dir=*/"", + /*log_file=*/""); ::testing::InitGoogleTest(&argc, argv); RAY_CHECK(argc == 3); ray::TEST_REDIS_SERVER_EXEC_PATH = argv[1]; diff --git a/src/ray/gcs/gcs_client/test/gcs_client_test.cc b/src/ray/gcs/gcs_client/test/gcs_client_test.cc index 6a75ca6d1cc2..7e5d7e5d3a65 100644 --- a/src/ray/gcs/gcs_client/test/gcs_client_test.cc +++ b/src/ray/gcs/gcs_client/test/gcs_client_test.cc @@ -1087,7 +1087,8 @@ int main(int argc, char **argv) { ray::RayLog::ShutDownRayLog, argv[0], ray::RayLogLevel::INFO, - /*log_dir=*/""); + /*log_dir=*/"", + /*log_file=*/""); ::testing::InitGoogleTest(&argc, argv); RAY_CHECK(argc == 3); ray::TEST_REDIS_SERVER_EXEC_PATH = argv[1]; diff --git a/src/ray/gcs/gcs_client/test/global_state_accessor_test.cc b/src/ray/gcs/gcs_client/test/global_state_accessor_test.cc index ba9781b082a5..388920f4fa57 100644 --- a/src/ray/gcs/gcs_client/test/global_state_accessor_test.cc +++ b/src/ray/gcs/gcs_client/test/global_state_accessor_test.cc @@ -343,7 +343,8 @@ int main(int argc, char **argv) { ray::RayLog::ShutDownRayLog, argv[0], ray::RayLogLevel::INFO, - /*log_dir=*/""); + /*log_dir=*/"", + /*log_file=*/""); ::testing::InitGoogleTest(&argc, argv); RAY_CHECK(argc == 3); ray::TEST_REDIS_SERVER_EXEC_PATH = argv[1]; diff --git a/src/ray/gcs/gcs_server/gcs_server_main.cc b/src/ray/gcs/gcs_server/gcs_server_main.cc index 8684846b2ed8..9443e460a967 100644 --- a/src/ray/gcs/gcs_server/gcs_server_main.cc +++ b/src/ray/gcs/gcs_server/gcs_server_main.cc @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include -#include #include "gflags/gflags.h" #include "ray/common/ray_config.h" @@ -44,19 +44,26 @@ DEFINE_string(ray_commit, "", "The commit hash of Ray."); namespace { // GCS server output filename. constexpr std::string_view kGcsServerLog = "gcs_server.out"; -} // namespace +} // namespace int main(int argc, char *argv[]) { gflags::ParseCommandLineFlags(&argc, &argv, true); // Backward compatibility notes: - // Due to historical reason, GCS server flushes all logging and stdout/stderr to a single file called `gcs_server.out`. - // To keep backward compatibility at best effort, we use the same filename as output, and disable log rotation by default. - const int64_t log_rotation_max_size = FLAGS_log_rotation_size <= 0 ? std::numeric_limits::max() : FLAGS_log_rotation_size; - RAY_CHECK_EQ(setenv("RAY_ROTATION_MAX_BYTES", std::to_string(log_rotation_max_size), /*overwrite=*/1)); - const std::string log_file = FLAGS_log_dir.empty() ? kGcsServerLog.data() : absl::StrFormat("%s/%s", FLAGS_log_dir, kGcsServerLog); - // TODO(hjiang): For the current implementation, we assume all logging are managed by spdlog, the caveat is there could be - // there's writing to stdout/stderr as well. The final solution is implement self-customized sink for spdlog, and redirect + // Due to historical reason, GCS server flushes all logging and stdout/stderr to a + // single file called `gcs_server.out`. To keep backward compatibility at best effort, + // we use the same filename as output, and disable log rotation by default. + const int64_t log_rotation_max_size = FLAGS_log_rotation_size <= 0 + ? std::numeric_limits::max() + : FLAGS_log_rotation_size; + RAY_CHECK_EQ(setenv( + "RAY_ROTATION_MAX_BYTES", std::to_string(log_rotation_max_size), /*overwrite=*/1)); + const std::string log_file = + FLAGS_log_dir.empty() ? kGcsServerLog.data() + : absl::StrFormat("%s/%s", FLAGS_log_dir, kGcsServerLog); + // TODO(hjiang): For the current implementation, we assume all logging are managed by + // spdlog, the caveat is there could be there's writing to stdout/stderr as well. The + // final solution is implement self-customized sink for spdlog, and redirect // stderr/stdout to the file descritor. Hold until it's confirmed necessary. InitShutdownRAII ray_log_shutdown_raii(ray::RayLog::StartRayLog, diff --git a/src/ray/gcs/store_client/test/redis_store_client_test.cc b/src/ray/gcs/store_client/test/redis_store_client_test.cc index aa8e863d3e85..7dd95aead0f2 100644 --- a/src/ray/gcs/store_client/test/redis_store_client_test.cc +++ b/src/ray/gcs/store_client/test/redis_store_client_test.cc @@ -373,7 +373,8 @@ int main(int argc, char **argv) { ray::RayLog::ShutDownRayLog, argv[0], ray::RayLogLevel::INFO, - /*log_dir=*/""); + /*log_dir=*/"", + /*log_file=*/""); ::testing::InitGoogleTest(&argc, argv); RAY_CHECK(argc == 3); ray::TEST_REDIS_SERVER_EXEC_PATH = argv[1]; diff --git a/src/ray/gcs/test/asio_test.cc b/src/ray/gcs/test/asio_test.cc index ef99ff21c9e4..3bd9db710409 100644 --- a/src/ray/gcs/test/asio_test.cc +++ b/src/ray/gcs/test/asio_test.cc @@ -89,7 +89,8 @@ int main(int argc, char **argv) { ray::RayLog::ShutDownRayLog, argv[0], ray::RayLogLevel::INFO, - /*log_dir=*/""); + /*log_dir=*/"", + /*log_file=*/""); ::testing::InitGoogleTest(&argc, argv); RAY_CHECK(argc == 3); ray::TEST_REDIS_SERVER_EXEC_PATH = argv[1]; diff --git a/src/ray/raylet/main.cc b/src/ray/raylet/main.cc index 5ae488e6e372..11c9b6b48315 100644 --- a/src/ray/raylet/main.cc +++ b/src/ray/raylet/main.cc @@ -125,7 +125,8 @@ int main(int argc, char *argv[]) { ray::RayLog::ShutDownRayLog, argv[0], ray::RayLogLevel::INFO, - /*log_dir=*/""); + /*log_dir=*/"", + /*log_file=*/""); ray::RayLog::InstallFailureSignalHandler(argv[0]); ray::RayLog::InstallTerminateHandler(); diff --git a/src/ray/raylet/worker_pool_test.cc b/src/ray/raylet/worker_pool_test.cc index 0da18903fdfe..0675751e03c0 100644 --- a/src/ray/raylet/worker_pool_test.cc +++ b/src/ray/raylet/worker_pool_test.cc @@ -2161,7 +2161,8 @@ int main(int argc, char **argv) { []() { ray::RayLog::ShutDownRayLog(); }, argv[0], ray::RayLogLevel::INFO, - /*log_dir=*/""); + /*log_dir=*/"", + /*log_file=*/""); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/ray/util/logging.cc b/src/ray/util/logging.cc index 5cebbdc6b776..751843c70107 100644 --- a/src/ray/util/logging.cc +++ b/src/ray/util/logging.cc @@ -311,16 +311,18 @@ void RayLog::InitLogFormat() { } } -/*static*/ std::string RayLog::GetLogOutputFilename(const std::string& log_dir, const std::string& log_file, const std::string& app_name) { +/*static*/ std::string RayLog::GetLogOutputFilename(const std::string &log_dir, + const std::string &log_file, + const std::string &app_name) { if (!log_file.empty()) { return log_file; } if (!log_dir.empty()) { - #ifdef _WIN32 - int pid = _getpid(); - #else - pid_t pid = getpid(); - #endif +#ifdef _WIN32 + int pid = _getpid(); +#else + pid_t pid = getpid(); +#endif return JoinPaths(log_dir, absl::StrFormat("%s_%d.log", app_name, pid)); } @@ -352,7 +354,8 @@ void RayLog::StartRayLog(const std::string &app_name, } } - const auto log_output_fname = GetLogOutputFilename(log_dir, log_file, app_name_without_path); + const auto log_output_fname = + GetLogOutputFilename(log_dir, log_file, app_name_without_path); if (!log_output_fname.empty()) { // Reset log pattern and level and we assume a log file can be rotated with // 10 files in max size 512M by default. @@ -382,9 +385,7 @@ void RayLog::StartRayLog(const std::string &app_name, spdlog::drop(RayLog::GetLoggerName()); } auto file_sink = std::make_shared( - log_output_fname, - log_rotation_max_size_, - log_rotation_file_num_); + log_output_fname, log_rotation_max_size_, log_rotation_file_num_); file_sink->set_level(level); sinks[0] = std::move(file_sink); } else { diff --git a/src/ray/util/logging.h b/src/ray/util/logging.h index 793299ef6d7f..f4a1a39fe7c7 100644 --- a/src/ray/util/logging.h +++ b/src/ray/util/logging.h @@ -260,8 +260,9 @@ class RayLog { /// \param severity_threshold Logging threshold for the program. /// \param log_dir Logging output directory name. /// \param log_file Logging output file name. - /// Both [log_dir] and [log_file] are used to determine log output filename; if both empty, the log won't output to file, but to stdout. - /// If both set, [log_file] has higher priority than [log_dir]. + /// Both [log_dir] and [log_file] are used to determine log output filename; if both + /// empty, the log won't output to file, but to stdout. If both set, [log_file] has + /// higher priority than [log_dir]. static void StartRayLog(const std::string &appName, RayLogLevel severity_threshold = RayLogLevel::INFO, const std::string &log_dir = "", @@ -310,7 +311,9 @@ class RayLog { const std::vector &expose_log_callbacks); /// Get log outout filename. - static std::string GetLogOutputFilename(const std::string& log_dir, const std::string& log_file, const std::string& app_name); + static std::string GetLogOutputFilename(const std::string &log_dir, + const std::string &log_file, + const std::string &app_name); template RayLog &operator<<(const T &t) { diff --git a/src/ray/util/tests/signal_test.cc b/src/ray/util/tests/signal_test.cc index c154cdaf0da5..fa34862d8d15 100644 --- a/src/ray/util/tests/signal_test.cc +++ b/src/ray/util/tests/signal_test.cc @@ -101,7 +101,8 @@ int main(int argc, char **argv) { ray::RayLog::ShutDownRayLog, argv[0], ray::RayLogLevel::INFO, - /*log_dir=*/""); + /*log_dir=*/"", + /*log_file=*/""); ray::RayLog::InstallFailureSignalHandler(argv[0]); ::testing::InitGoogleTest(&argc, argv); int failed = RUN_ALL_TESTS();