Skip to content

Server Logging Rules (obsolete)

Louis Williams edited this page Jul 7, 2022 · 3 revisions

WARNING

This document is largely obsolete. Please refer to docs/logging.md for up-to-date guidance on logging.


Basic Rules

  • cout/cerr should never be used

  • Include mongo/util/log.h to use the LOG() helper macro

  • Declare a log component before the first #include statement in a .cpp file to assign a default log component to log messages.

    #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kStorage
    
    #include ...
    

Normal Logging

  • 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 stream are executed.

    LOG( int x ) << ...
    
  • Informational

    log() << ...
    
  • Warnings

    • recoverable, e.g. replica set node down
    warning() << ...
    
  • Errors

    • unexpected system state (disk full)
    • internal code errors
    error() << ...