Do not fail on unsuccessful FileLog.init.
GitOrigin-RevId: c31bcf155821a973b431234d76aa83e3b0e281a0
This commit is contained in:
parent
6d21c7c912
commit
662471ea48
@ -30,8 +30,11 @@ void Log::set_file_path(string file_path) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_log.init(file_path, max_log_file_size);
|
if (file_log.init(file_path, max_log_file_size)) {
|
||||||
log_interface = &ts_log;
|
log_interface = &ts_log;
|
||||||
|
} else {
|
||||||
|
LOG(FATAL) << "Can't init file log";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::set_max_file_size(int64 max_file_size) {
|
void Log::set_max_file_size(int64 max_file_size) {
|
||||||
|
@ -2948,10 +2948,9 @@ void main(int argc, char **argv) {
|
|||||||
if (*arg == '\0' && i + 1 < argc) {
|
if (*arg == '\0' && i + 1 < argc) {
|
||||||
arg = argv[++i];
|
arg = argv[++i];
|
||||||
}
|
}
|
||||||
file_log.init(arg);
|
if (file_log.init(arg) && file_log.init(arg) && file_log.init(arg)) {
|
||||||
file_log.init(arg);
|
|
||||||
file_log.init(arg);
|
|
||||||
log_interface = &ts_log;
|
log_interface = &ts_log;
|
||||||
|
}
|
||||||
} else if (!std::strcmp(argv[i], "-W")) {
|
} else if (!std::strcmp(argv[i], "-W")) {
|
||||||
get_chat_list = true;
|
get_chat_list = true;
|
||||||
} else if (!std::strcmp(argv[i], "--disable-network") || !std::strcmp(argv[i], "-n")) {
|
} else if (!std::strcmp(argv[i], "--disable-network") || !std::strcmp(argv[i], "-n")) {
|
||||||
|
@ -17,16 +17,26 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
void FileLog::init(string path, int64 rotate_threshold) {
|
bool FileLog::init(string path, int64 rotate_threshold) {
|
||||||
fd_.close();
|
if (path == path_) {
|
||||||
path_ = std::move(path);
|
set_rotate_threshold(rotate_threshold);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
auto r_fd = FileFd::open(path_, FileFd::Create | FileFd::Write | FileFd::Append);
|
auto r_fd = FileFd::open(path, FileFd::Create | FileFd::Write | FileFd::Append);
|
||||||
LOG_IF(FATAL, r_fd.is_error()) << "Can't open log: " << r_fd.error();
|
if (r_fd.is_error()) {
|
||||||
|
LOG(ERROR) << "Can't open log: " << r_fd.error();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd_.close();
|
||||||
fd_ = r_fd.move_as_ok();
|
fd_ = r_fd.move_as_ok();
|
||||||
Fd::duplicate(fd_.get_fd(), Fd::Stderr()).ignore();
|
Fd::duplicate(fd_.get_fd(), Fd::Stderr()).ignore();
|
||||||
|
|
||||||
|
path_ = std::move(path);
|
||||||
size_ = fd_.get_size();
|
size_ = fd_.get_size();
|
||||||
rotate_threshold_ = rotate_threshold;
|
rotate_threshold_ = rotate_threshold;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileLog::set_rotate_threshold(int64 rotate_threshold) {
|
void FileLog::set_rotate_threshold(int64 rotate_threshold) {
|
||||||
|
@ -17,7 +17,7 @@ class FileLog : public LogInterface {
|
|||||||
static constexpr int64 DEFAULT_ROTATE_THRESHOLD = 10 * (1 << 20);
|
static constexpr int64 DEFAULT_ROTATE_THRESHOLD = 10 * (1 << 20);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void init(string path, int64 rotate_threshold = DEFAULT_ROTATE_THRESHOLD);
|
bool init(string path, int64 rotate_threshold = DEFAULT_ROTATE_THRESHOLD);
|
||||||
|
|
||||||
void set_rotate_threshold(int64 rotate_threshold);
|
void set_rotate_threshold(int64 rotate_threshold);
|
||||||
|
|
||||||
|
@ -55,8 +55,9 @@ void TestsRunner::init(string dir) {
|
|||||||
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(WARNING));
|
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(WARNING));
|
||||||
chdir(dir).ensure();
|
chdir(dir).ensure();
|
||||||
LOG(WARNING) << "Redirect log into " << tag("file", dir + TD_DIR_SLASH + "log.txt");
|
LOG(WARNING) << "Redirect log into " << tag("file", dir + TD_DIR_SLASH + "log.txt");
|
||||||
file_log.init("log.txt", std::numeric_limits<int64>::max());
|
if (file_log.init("log.txt", std::numeric_limits<int64>::max())) {
|
||||||
log_interface = &ts_log;
|
log_interface = &ts_log;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
Reference in New Issue
Block a user