|
|
@ -29,9 +29,9 @@ LogMessage::LogMessage(const char* file,
|
|
|
|
bool out_to_file /* = false */)
|
|
|
|
bool out_to_file /* = false */)
|
|
|
|
: level_(level), verbose_(verbose), out_to_file_(out_to_file) {
|
|
|
|
: level_(level), verbose_(verbose), out_to_file_(out_to_file) {
|
|
|
|
if (FLAGS_logtostderr == 0) {
|
|
|
|
if (FLAGS_logtostderr == 0) {
|
|
|
|
stream_ = std::shared_ptr<std::ostream>(&std::cout);
|
|
|
|
stream_ = static_cast<std::ostream*>(&std::cout);
|
|
|
|
} else if (FLAGS_logtostderr == 1) {
|
|
|
|
} else if (FLAGS_logtostderr == 1) {
|
|
|
|
stream_ = std::shared_ptr<std::ostream>(&std::cerr);
|
|
|
|
stream_ = static_cast<std::ostream*>(&std::cerr);
|
|
|
|
} else if (out_to_file_) {
|
|
|
|
} else if (out_to_file_) {
|
|
|
|
// logfile
|
|
|
|
// logfile
|
|
|
|
lock_.lock();
|
|
|
|
lock_.lock();
|
|
|
@ -46,7 +46,7 @@ LogMessage::~LogMessage() {
|
|
|
|
lock_.unlock();
|
|
|
|
lock_.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (level_ == FATAL) {
|
|
|
|
if (verbose_ && level_ == FATAL) {
|
|
|
|
std::abort();
|
|
|
|
std::abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -73,30 +73,20 @@ void LogMessage::init(const char* file, int line) {
|
|
|
|
std::string("log." + proc_name + ".log.FATAL." + tmp + "." + pid);
|
|
|
|
std::string("log." + proc_name + ".log.FATAL." + tmp + "." + pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::ofstream ofs;
|
|
|
|
thread_local static std::ofstream ofs;
|
|
|
|
if (level_ == DEBUG) {
|
|
|
|
if (level_ == DEBUG) {
|
|
|
|
stream_ = std::make_shared<std::ofstream>(
|
|
|
|
ofs.open(s_debug_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
s_debug_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
|
|
|
|
// ofs.open(s_debug_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
|
|
|
|
} else if (level_ == INFO) {
|
|
|
|
} else if (level_ == INFO) {
|
|
|
|
// ofs.open(s_warning_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
ofs.open(s_info_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
stream_ = std::make_shared<std::ofstream>(
|
|
|
|
|
|
|
|
s_warning_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
|
|
|
|
} else if (level_ == WARNING) {
|
|
|
|
} else if (level_ == WARNING) {
|
|
|
|
// ofs.open(s_warning_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
ofs.open(s_warning_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
stream_ = std::make_shared<std::ofstream>(
|
|
|
|
|
|
|
|
s_warning_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
|
|
|
|
} else if (level_ == ERROR) {
|
|
|
|
} else if (level_ == ERROR) {
|
|
|
|
// ofs.open(s_error_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
ofs.open(s_error_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
stream_ = std::make_shared<std::ofstream>(
|
|
|
|
|
|
|
|
s_error_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// ofs.open(s_fatal_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
ofs.open(s_fatal_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
stream_ = std::make_shared<std::ofstream>(
|
|
|
|
|
|
|
|
s_fatal_logfile_.c_str(), std::ios::out | std::ios::app);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// stream_ = &ofs;
|
|
|
|
stream_ = &ofs;
|
|
|
|
|
|
|
|
|
|
|
|
stream() << tmp << " " << file << " line " << line << "; ";
|
|
|
|
stream() << tmp << " " << file << " line " << line << "; ";
|
|
|
|
stream() << std::flush;
|
|
|
|
stream() << std::flush;
|
|
|
|