Listing 8

// 6BgThreads.cpp

class BgLogger: public ErrorLogger
{
public:
  virtual void Log( const string& msg )
  {
    boost::mutex::scoped_lock lock(mtx_);
    clog << "  [BG]" << msg;
  }
};
//----------------------------------------------------------
class FgLogger : public ErrorLogger
{
  // set up foreground logging...
};
//----------------------------------------------------------
struct LoggingBackgroundThread
{
  // this is a boost::thread function object that
  // does some work and calls Error() and Log()
};
//----------------------------------------------------------
int main( int argc, char* argv[])
{
  ErrorLogger::PushLogger(ErrorLoggerPtr(new FgLogger));
  ErrorLogger::SetBgLogger(ErrorLoggerPtr(new BgLogger));
  for( int ii = 1; ii <= 5; ++ii )
  {
    LoggingBackgroundThread    thrd(ii);
    boost::thread launch(thrd);
  }
  // do some logging from the foreground thread...
}