@@ -77,6 +77,10 @@ DEFINE_NON_RUNTIME_string(ref_counted_debug_type_name_regex, "",
7777 " Regex for type names for debugging RefCounted / scoped_refptr based classes. "
7878 " An empty string disables RefCounted debug logging." );
7979
80+ DEFINE_RUNTIME_bool (disable_core_dumps_on_fatal, true ,
81+ " Whether to disable core dumps when a FATAL log is encountered. "
82+ " Set to false to allow full core dumps on FATAL for debugging purposes." );
83+
8084DECLARE_bool (TEST_running_test);
8185
8286const char * kProjName = " yb" ;
@@ -446,36 +450,41 @@ LogFatalHandlerSink::~LogFatalHandlerSink() {
446450void LogFatalHandlerSink::send (
447451 google::LogSeverity severity, const char * full_filename, const char * base_filename,
448452 int line_number, const struct tm * tm_time, const char * message, size_t message_len) {
449- if (severity == LogSeverity::SEVERITY_FATAL) {
453+ if (severity != LogSeverity::SEVERITY_FATAL) {
454+ return ;
455+ }
456+
457+ if (FLAGS_disable_core_dumps_on_fatal) {
450458 DisableCoreDumps ();
451- string timestamp_for_filename;
452- StringAppendStrftime (×tamp_for_filename, " %Y-%m-%dT%H_%M_%S" , tm_time);
453- const string output_path = Format (
454- " $0.$1.pid$2.txt" , GetFatalDetailsPathPrefix (), timestamp_for_filename, getpid ());
455- // Use a line format similar to glog with a couple of slight differences:
456- // - Report full file path.
457- // - Time has no microsecond component.
458- string output_str = " F" ;
459- StringAppendStrftime (&output_str, " %Y%m%d %H:%M:%S" , tm_time);
460- // TODO: append thread id if we need to.
461- StringAppendF (&output_str, " %s:%d] " , full_filename, line_number);
462- output_str += std::string (message, message_len);
463- output_str += " \n " ;
464- output_str += GetStackTrace ();
465-
466- ofstream out_f (output_path);
467- if (out_f) {
468- out_f << output_str << endl;
469- }
470- if (out_f.bad ()) {
471- cerr << " Failed to write fatal failure details to " << output_path << endl;
472- } else {
473- cerr << " Fatal failure details written to " << output_path << endl;
474- }
475- // Also output fatal failure details to stderr so make sure we have a properly symbolized stack
476- // trace in the context of a test.
477- cerr << output_str << endl;
478459 }
460+
461+ string timestamp_for_filename;
462+ StringAppendStrftime (×tamp_for_filename, " %Y-%m-%dT%H_%M_%S" , tm_time);
463+ const string output_path = Format (
464+ " $0.$1.pid$2.txt" , GetFatalDetailsPathPrefix (), timestamp_for_filename, getpid ());
465+ // Use a line format similar to glog with a couple of slight differences:
466+ // - Report full file path.
467+ // - Time has no microsecond component.
468+ string output_str = " F" ;
469+ StringAppendStrftime (&output_str, " %Y%m%d %H:%M:%S" , tm_time);
470+ // TODO: append thread id if we need to.
471+ StringAppendF (&output_str, " %s:%d] " , full_filename, line_number);
472+ output_str += std::string (message, message_len);
473+ output_str += " \n " ;
474+ output_str += GetStackTrace ();
475+
476+ ofstream out_f (output_path);
477+ if (out_f) {
478+ out_f << output_str << endl;
479+ }
480+ if (out_f.bad ()) {
481+ cerr << " Failed to write fatal failure details to " << output_path << endl;
482+ } else {
483+ cerr << " Fatal failure details written to " << output_path << endl;
484+ }
485+ // Also output fatal failure details to stderr so make sure we have a properly symbolized stack
486+ // trace in the context of a test.
487+ cerr << output_str << endl;
479488}
480489
481490namespace logging_internal {
0 commit comments