reSIProcate/rutil  9694
Public Member Functions | Public Attributes | Protected Attributes | Friends
resip::Log::ThreadData Class Reference

#include <Log.hxx>

Collaboration diagram for resip::Log::ThreadData:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ThreadData (LocalLoggerId id, Type type=Cout, Level level=Info, const char *logFileName=NULL, ExternalLogger *pExternalLogger=NULL)
 ~ThreadData ()
void set (Type type=Cout, Level level=Info, const char *logFileName=NULL, ExternalLogger *pExternalLogger=NULL)
LocalLoggerId id () const
unsigned int maxLineCount ()
unsigned int maxByteCount ()
std::ostream & Instance (unsigned int bytesToWrite)
 Return logger stream instance, creating it if needed.
void reset ()
 Frees logger stream.

Public Attributes

volatile Level mLevel
volatile unsigned int mMaxLineCount
volatile unsigned int mMaxByteCount
ExternalLoggermExternalLogger

Protected Attributes

const LocalLoggerId mId
Type mType
Data mLogFileName
std::ostream * mLogger
unsigned int mLineCount

Friends

class Guard

Detailed Description

Definition at line 266 of file Log.hxx.


Constructor & Destructor Documentation

resip::Log::ThreadData::ThreadData ( LocalLoggerId  id,
Type  type = Cout,
Level  level = Info,
const char *  logFileName = NULL,
ExternalLogger pExternalLogger = NULL 
) [inline]

Definition at line 269 of file Log.hxx.

References mLogFileName.

               : mLevel(level),
                 mMaxLineCount(0),
                 mMaxByteCount(0),
                 mExternalLogger(pExternalLogger),
                 mId(id),
                 mType(type),
                 mLogger(NULL),
                 mLineCount(0)
            {
               if (logFileName)
               {
                  mLogFileName = logFileName;
               }
            }
resip::Log::ThreadData::~ThreadData ( ) [inline]

Definition at line 286 of file Log.hxx.

References reset().

{ reset(); }

Here is the call graph for this function:


Member Function Documentation

LocalLoggerId resip::Log::ThreadData::id ( ) const [inline]

Definition at line 302 of file Log.hxx.

References mId.

Referenced by resip::Log::id(), and resip::Log::setThreadLocalLogger().

{return mId;}
std::ostream & Log::ThreadData::Instance ( unsigned int  bytesToWrite)

Return logger stream instance, creating it if needed.

Definition at line 775 of file Log.cxx.

References resip::Data::c_str(), resip::Log::Cerr, resip::Log::Cout, resip::Log::File, and resip::Log::Syslog.

{
//   std::cerr << "Log::ThreadData::Instance() id=" << mId << " type=" << mType <<  std::endl;
   switch (mType)
   {
      case Log::Syslog:
         if (mLogger == 0)
         {
            std::cerr << "Creating a syslog stream" << std::endl;
            mLogger = new SysLogStream;
         }
         return *mLogger;

      case Log::Cerr:
         return std::cerr;

      case Log::Cout:
         return std::cout;

      case Log::File:
         if (mLogger == 0 ||
             (maxLineCount() && mLineCount >= maxLineCount()) ||
             (maxByteCount() && ((unsigned int)mLogger->tellp()+bytesToWrite) >= maxByteCount()))
         {
            std::cerr << "Creating a logger for file \"" << mLogFileName.c_str() << "\"" << std::endl;
            Data logFileName(mLogFileName != "" ? mLogFileName : "resiprocate.log");
            if (mLogger)
            {
               Data oldLogFileName(logFileName + ".old");
               delete mLogger;
               // Keep one backup file: Delete .old file, Rename log file to .old
               // Could be expanded in the future to keep X backup log files
               remove(oldLogFileName.c_str());
               rename(logFileName.c_str(), oldLogFileName.c_str());
            }
            // Append to log if we have a line count or byte count limit - otherwise truncate
            mLogger = new std::ofstream(logFileName.c_str(), std::ios_base::out | ((maxLineCount() > 0 || maxByteCount() > 0) ? std::ios_base::app : std::ios_base::trunc));
            mLineCount = 0;
         }
         mLineCount++;
         return *mLogger;
      default:
         assert(0);
         return std::cout;
   }
}

Here is the call graph for this function:

unsigned int resip::Log::ThreadData::maxByteCount ( ) [inline]

Definition at line 304 of file Log.hxx.

References resip::Log::MaxByteCount, and mMaxByteCount.

{ return mMaxByteCount ? mMaxByteCount : MaxByteCount; }  // return local max, if not set use global max
unsigned int resip::Log::ThreadData::maxLineCount ( ) [inline]

Definition at line 303 of file Log.hxx.

References resip::Log::MaxLineCount, and mMaxLineCount.

{ return mMaxLineCount ? mMaxLineCount : MaxLineCount; }  // return local max, if not set use global max
void Log::ThreadData::reset ( )

Frees logger stream.

Definition at line 823 of file Log.cxx.

Referenced by ~ThreadData().

{
   delete mLogger;
   mLogger = NULL;
}
void resip::Log::ThreadData::set ( Type  type = Cout,
Level  level = Info,
const char *  logFileName = NULL,
ExternalLogger pExternalLogger = NULL 
) [inline]

Definition at line 288 of file Log.hxx.

References resip::Log::level(), mExternalLogger, mLevel, mLogFileName, and mType.

            {
               mType = type;
               mLevel = level;

               if (logFileName)
               {
                  mLogFileName = logFileName;
               }
               mExternalLogger = pExternalLogger;
            }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class Guard [friend]

Definition at line 315 of file Log.hxx.


Member Data Documentation

Definition at line 312 of file Log.hxx.

Referenced by resip::Log::getExternal(), and set().

Definition at line 316 of file Log.hxx.

Referenced by id().

Definition at line 309 of file Log.hxx.

Referenced by resip::Log::level(), set(), and resip::Log::setLevel().

unsigned int resip::Log::ThreadData::mLineCount [protected]

Definition at line 320 of file Log.hxx.

Definition at line 318 of file Log.hxx.

Referenced by set(), and ThreadData().

std::ostream* resip::Log::ThreadData::mLogger [protected]

Definition at line 319 of file Log.hxx.

Definition at line 311 of file Log.hxx.

Referenced by maxByteCount(), and resip::Log::setMaxByteCount().

Definition at line 310 of file Log.hxx.

Referenced by maxLineCount(), and resip::Log::setMaxLineCount().

Definition at line 317 of file Log.hxx.

Referenced by set(), and resip::Log::Guard::~Guard().


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