libmoost
moost::logging::global_scoped_logger Class Reference

handles scoped logging gracefully across the whole project. global_scoped_logger takes a scoped_logger and makes it available across the whole project without having to pass the object around. global_scoped_logger is thread safe because each object is thread specific. In order to be able to use global_scoped_logger you need to define the scope where the logging will operate: More...

#include <global_scoped_logger.h>

List of all members.

Public Member Functions

 global_scoped_logger (const std::string &name)
template<typename TTimer >
 global_scoped_logger (const std::string &name, TTimer &start)
 ~global_scoped_logger ()

Private Attributes

global_scoped_logger_tm_pScopedLogging

Detailed Description

handles scoped logging gracefully across the whole project. global_scoped_logger takes a scoped_logger and makes it available across the whole project without having to pass the object around. global_scoped_logger is thread safe because each object is thread specific. In order to be able to use global_scoped_logger you need to define the scope where the logging will operate:

void someFunction()
{
  MLOG_SCOPED_GLOBAL_FUNC_INIT;
  // alternatively one can specify the name with:
  // MLOG_SCOPED_GLOBAL_NAMED_INIT("someName");

  // now it's time to get the logger
  MLOG_SCOPED_GLOBAL_GET_LOGGER(logger);

  MLOG(MLOG_LEVEL_INFO, logger, "log this: " << 944534634578UL);
}

Now, this alone would not be very useful. The true power of global_scoped_logger is that you have access of the logger everywhere in your code without having to pass it around! Let's say you defined a few functions before "someFunction()":

void foo()
{
   MLOG_SCOPED_GLOBAL_GET_LOGGER(logger);
   MLOG(MLOG_LEVEL_INFO, logger, "I am in foo!");
}

void bar()
{
   foo(); // nothing needs to be passed here
}
Note:
Do not forget to include the moost library in your linking or it will not find the external for m_pScopedLogging!

Definition at line 82 of file global_scoped_logger.h.


Constructor & Destructor Documentation

moost::logging::global_scoped_logger::global_scoped_logger ( const std::string &  name) [inline]

Definition at line 86 of file global_scoped_logger.h.

template<typename TTimer >
moost::logging::global_scoped_logger::global_scoped_logger ( const std::string &  name,
TTimer &  start 
) [inline]

Definition at line 91 of file global_scoped_logger.h.


Member Data Documentation


The documentation for this class was generated from the following file: