Logger Class Reference

#include <Debug.h>

Collaboration diagram for Logger:

Collaboration graph
[legend]

Public Member Functions

int log (LogLevel level, char *filename, int lineNo, char *format,...)
int createLogRecord (LogLevel level, char *filename, int lineNo, char *message, char **in)
DbRetVal startLogger (char *filename, bool isCreate=false)
void stopLogger ()

Detailed Description

Definition at line 98 of file Debug.h.


Member Function Documentation

int Logger::createLogRecord ( LogLevel  level,
char *  filename,
int  lineNo,
char *  message,
char **  in 
)

Definition at line 17 of file Logger.cxx.

References os::getpid(), os::getthrid(), os::gettimeofday(), levelNames, os::localtime(), and MAX_TRACE_LOG_LENGTH.

Referenced by log().

00019 {
00020     char    tempBuffer[25];
00021     struct timeval timeStamp;
00022     os::gettimeofday(&timeStamp);
00023     struct tm*      tempTm = os::localtime(&timeStamp.tv_sec);
00024     strftime(tempBuffer, 25, "%d/%m/%Y %H:%M:%S.", tempTm);
00025     snprintf(*buffer, MAX_TRACE_LOG_LENGTH, "%s::%s:%d::%s::%d::%d::%lu::%s\n",
00026         levelNames[level], tempBuffer, timeStamp.tv_usec,
00027         filename, lineNo,
00028         os::getpid(),
00029         os::getthrid(),
00030         message);
00031     return 0;
00032 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Logger::log ( LogLevel  level,
char *  filename,
int  lineNo,
char *  format,
  ... 
)

Definition at line 36 of file Logger.cxx.

References createLogRecord(), ErrLockTimeOut, os::fsync(), LogOff, MAX_TRACE_LOG_LENGTH, printError, and os::write().

00038 {
00039     if (LogOff == configLevel) return 0;
00040     if (level <= configLevel )
00041     {
00042         va_list ap;
00043         char mesgBuf[1024]; 
00044         va_start(ap, format);
00045 
00046         int err = ::vsnprintf(mesgBuf, sizeof(mesgBuf), format,ap);
00047         if(err < 0) {
00048             return err;
00049         } 
00050         char *buffer = new char[MAX_TRACE_LOG_LENGTH];
00051         createLogRecord(level, filename, lineNo, mesgBuf, &buffer);
00052         //TODO::There is some issue in locking. Need to look into this and then
00053         //uncomment the below lines
00054         //int ret = mutex_.tryLock(5, 100000);
00055         int ret = 0;
00056         if (ret != 0)
00057         {
00058             printError(ErrLockTimeOut,"Unable to acquire logger Mutex");
00059             delete[] buffer;
00060             return -1;
00061         }        
00062         os::write(fdLog, buffer, strlen(buffer));
00063         os::fsync(fdLog);
00064         //mutex_.releaseLock();
00065         delete[] buffer;
00066     }
00067     return 0;
00068 }

Here is the call graph for this function:

DbRetVal Logger::startLogger ( char *  filename,
bool  isCreate = false 
)

Definition at line 70 of file Logger.cxx.

References ErrSysInit, file, fileOpenAppend, fileOpenCreat, LogFinest, OK, os::openFile(), and printError.

Referenced by main(), and Connection::open().

00071 {
00072     char file[256];
00073     int i =0;
00074     if (isCreate) 
00075     {
00076         while (true)
00077         {
00078             sprintf(file, "%s.%d", filename, i);
00079             //check if file exists. If not create it
00080             if (::access(file, F_OK) != 0 ) break;
00081             i++;
00082         }
00083         fdLog = os::openFile(file, fileOpenCreat,0);
00084     }
00085     else
00086     {
00087         int newlyCreatedID =0;
00088         while (true)
00089         {
00090             sprintf(file, "%s.%d", filename, i);
00091             //check if file exists. If not create it
00092             if (::access(file, F_OK) != 0 ) break;
00093             newlyCreatedID = i;
00094             i++;
00095         }
00096         sprintf(file, "%s.%d", filename, newlyCreatedID );
00097         fdLog = os::openFile(file, fileOpenAppend,0);
00098     }
00099     if (fdLog == -1)
00100     {
00101         printError(ErrSysInit,"Unable to create log file. Check whether server started\n");
00102         return ErrSysInit;
00103     }
00104     //TODO::get this value from configuration file
00105     configLevel= LogFinest;
00106     return OK;
00107 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Logger::stopLogger (  ) 

Definition at line 109 of file Logger.cxx.

References os::closeFile().

Referenced by Connection::close(), and main().

00110 {
00111     os::closeFile(fdLog);
00112 }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 22:48:39 2008 for csql by  doxygen 1.4.7