Write logs to files instead of printing them to stdout

This commit is contained in:
Philipp Moritz
2016-06-19 12:45:34 -07:00
parent c7e14e0a8b
commit 912fd5cc81
11 changed files with 141 additions and 45 deletions
+39
View File
@@ -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);
}
}