mirror of
https://github.com/wassname/ray.git
synced 2026-09-12 12:51:15 +08:00
Write logs to files instead of printing them to stdout
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#include "utils.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "ray/ray.h"
|
||||
|
||||
std::string::iterator split_ip_address(std::string& ip_address) {
|
||||
if (ip_address[0] == '[') { // IPv6
|
||||
auto split_end = std::find(ip_address.begin() + 1, ip_address.end(), ']');
|
||||
if(split_end != ip_address.end()) {
|
||||
split_end++;
|
||||
}
|
||||
if(split_end != ip_address.end() && *split_end == ':') {
|
||||
return split_end;
|
||||
}
|
||||
RAY_CHECK(false, "ip address should contain a port number");
|
||||
} else { // IPv4
|
||||
auto split_point = std::find(ip_address.rbegin(), ip_address.rend(), ':').base();
|
||||
RAY_CHECK_NEQ(split_point, ip_address.begin(), "ip address should contain a port number");
|
||||
return split_point;
|
||||
}
|
||||
}
|
||||
|
||||
const char* get_cmd_option(char** begin, char** end, const std::string& option) {
|
||||
char** it = std::find(begin, end, option);
|
||||
if (it != end && ++it != end) {
|
||||
return *it;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void create_log_dir_or_die(const char* log_file_name) {
|
||||
boost::filesystem::path log_file_path(log_file_name);
|
||||
boost::system::error_code returned_error;
|
||||
boost::filesystem::create_directories(log_file_path.parent_path(), returned_error);
|
||||
if (returned_error) {
|
||||
RAY_CHECK(false, "Failed to create directory for " << log_file_name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user