Changeset 5896 for branches/newapi

Show
Ignore:
Timestamp:
12/02/07 02:11:45 (12 months ago)
Author:
erijo
Message:

Added functions for setting and getting the thread's log instance.

Location:
branches/newapi/licq/src/util
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/newapi/licq/src/util/log.cpp

    r5498 r5896  
    1919 
    2020#include "licq/interface/logsink.h" 
     21#include "licq/thread/threadspecific.h" 
    2122#include "util/log.h" 
     23#include "util/tr.h" 
    2224 
    2325#include <cassert> 
     
    2527#include <time.h> 
    2628 
     29static Licq::ThreadSpecific<LicqDaemon::Log> ThreadLogs; 
     30 
    2731LicqDaemon::Log::Log(const std::string& owner, Licq::LogSink* sink) 
    2832  : myOwner(owner), mySink(sink) 
    2933{ 
    3034  assert(mySink != NULL); 
     35} 
     36 
     37void LicqDaemon::Log::setThreadLog(const Log* log) 
     38{ 
     39  if (ThreadLogs.hasData()) 
     40  { 
     41    ThreadLogs.getData()->fatal() << 
     42        tr("LicqDaemon::Log::setThreadLog called more than once"); 
     43    ::abort(); 
     44  } 
     45  ThreadLogs.setData(log); 
     46} 
     47 
     48LicqDaemon::Log* LicqDaemon::Log::getThreadLog() 
     49{ 
     50  assert(ThreadLogs.hasData()); 
     51  return ThreadLogs.getData(); 
    3152} 
    3253 
  • branches/newapi/licq/src/util/log.h

    r5498 r5896  
    4444  Log(const std::string& owner, Licq::LogSink* sink); 
    4545 
     46  /** 
     47   * Makes @a log the default log for the calling thread. @a log will 
     48   * be automatically deleted when the thread exits. This method may 
     49   * only be called once per thread. 
     50   * 
     51   * @see getThreadLog() 
     52   */ 
     53  static void setThreadLog(const Log* log); 
     54 
     55  /** 
     56   * @returns The default log for the calling thread. setThreadLog() 
     57   * must have been called by the calling thread before calling this 
     58   * method. 
     59   * 
     60   * @see setThreadLog() 
     61   */ 
     62  static Log* getThreadLog(); 
     63 
    4664  // From Licq::Log 
    4765  void log(Level level, const std::string& msg);