proxygen
FatalHelper.cpp File Reference
#include <folly/init/Init.h>
#include <folly/logging/xlog.h>
#include <folly/portability/Stdlib.h>
#include <iostream>

Go to the source code of this file.

Functions

 DEFINE_string (category,"","Crash with a message to this category instead of the default")
 
 DEFINE_bool (crash, true,"Crash with a fatal log message.")
 
 DEFINE_bool (check_debug, false,"Print whether this binary was built in debug mode ""and then exit successfully")
 
 DEFINE_bool (fail_fatal_xlog_if, false,"Fail an XLOG_IF(FATAL) check.")
 
 DEFINE_bool (fail_dfatal_xlog_if, false,"Fail an XLOG_IF(DFATAL) check.")
 
 DEFINE_bool (fail_xcheck, false,"Fail an XCHECK() test.")
 
 DEFINE_bool (fail_xcheck_nomsg, false,"Fail an XCHECK() test with no additional message.")
 
 DEFINE_bool (fail_xdcheck, false,"Fail an XDCHECK() test.")
 
std::string fbLogFatalCheck ()
 
int main (int argc, char *argv[])
 

Function Documentation

DEFINE_bool ( crash  ,
true  ,
"Crash with a fatal log message."   
)
DEFINE_bool ( check_debug  ,
false  ,
"Print whether this binary was built in debug mode ""and then exit successfully"   
)
DEFINE_bool ( fail_fatal_xlog_if  ,
false  ,
"Fail an XLOG_IF(FATAL) check."   
)
DEFINE_bool ( fail_dfatal_xlog_if  ,
false  ,
"Fail an XLOG_IF(DFATAL) check."   
)
DEFINE_bool ( fail_xcheck  ,
false  ,
"Fail an XCHECK() test."   
)
DEFINE_bool ( fail_xcheck_nomsg  ,
false  ,
"Fail an XCHECK() test with no additional message."   
)
DEFINE_bool ( fail_xdcheck  ,
false  ,
"Fail an XDCHECK() test."   
)
DEFINE_string ( category  ,
""  ,
"Crash with a message to this category instead of the default"   
)
std::string fbLogFatalCheck ( )

Definition at line 88 of file FatalHelper.cpp.

References FB_LOG.

88  {
89  folly::Logger logger("some.category");
90  FB_LOG(logger, FATAL) << "we always crash";
91  // This function mostly exists to make sure the compiler does not warn
92  // about a missing return statement here.
93 }
#define FB_LOG(logger, level,...)
Definition: Logger.h:34
int main ( int  argc,
char *  argv[] 
)

Definition at line 98 of file FatalHelper.cpp.

References bm::init(), folly::kIsDebug, XCHECK, XDCHECK, and XLOG_IF.

98  {
99  auto init = folly::Init(&argc, &argv);
100 
101  if (FLAGS_check_debug) {
102  std::cout << "DEBUG=" << static_cast<int>(folly::kIsDebug) << "\n";
103  return 0;
104  }
105 
106  XLOG_IF(FATAL, FLAGS_fail_fatal_xlog_if) << "--fail_fatal_xlog_if specified!";
107  XLOG_IF(DFATAL, FLAGS_fail_dfatal_xlog_if)
108  << "--fail_dfatal_xlog_if specified!";
109  XCHECK(!FLAGS_fail_xcheck) << ": --fail_xcheck specified!";
110  XCHECK(!FLAGS_fail_xcheck_nomsg);
111  XDCHECK(!FLAGS_fail_xdcheck) << ": --fail_xdcheck specified!";
112 
113  // Do most of the work in a separate helper function.
114  //
115  // The main reason for putting this in a helper function is to ensure that
116  // the compiler does not warn about missing return statements on XLOG(FATAL)
117  // code paths. Unfortunately it appears like some compilers always suppress
118  // this warning for main().
119  return runHelper();
120 }
constexpr auto kIsDebug
Definition: Portability.h:264
void init()
char ** argv
#define XCHECK(cond,...)
Definition: xlog.h:332
#define XLOG_IF(level, cond,...)
Definition: xlog.h:68
#define XDCHECK(cond,...)
Definition: xlog.h:346