Server Logging Rules¶
cout/cerr should never be used
except early in process startup before the log() system is initialized
For such cases, it would be good to use cerr, but right now there is a mix of cout and cerr
Include log_internal.h to use the LOG() helper macro
- Use MONGO_LOG() instead of LOG() for code included by C++ driver headers.
Debugging with levels of verbosity. See the -v command line option (default level is 0). If the global log level is less than x, no functions in the steam are executed.
LOG( int x ) << ...
log() << ...
LOGSOME() << ...
- recoverable, e.g. replica set node down
warning() << ...
- unexpected system state (disk full)
- internal code errors
error() << ...
- PRINT( x )
Prints expression text and value. Can also accept expressions like PRINT(x.method())
Prints file and line. Good for tracing execution.
Shows a stack trace. Alternative to using a debugger.
- GEODEBUG, etc...
Used for incredibly verbose logging for a section of code that has to be turned on at compile time