Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "log.h"
00023 #include "clog.h"
00024 #include <pthread.h>
00025 #include <stdio.h>
00026 #include <stdarg.h>
00027 #include <string.h>
00028 #include <iostream>
00029
00030 namespace Barry {
00031
00032 extern bool __data_dump_mode__;
00033 extern std::ostream *LogStream;
00034 extern pthread_mutex_t LogStreamMutex;
00035
00036 LogLock::LogLock()
00037 {
00038 while( pthread_mutex_lock(&LogStreamMutex) != 0 )
00039 ;
00040 }
00041
00042 LogLock::~LogLock()
00043 {
00044 pthread_mutex_unlock(&LogStreamMutex);
00045 }
00046
00047
00048 bool LogVerbose()
00049 {
00050 return __data_dump_mode__;
00051 }
00052
00053 std::ostream* GetLogStream()
00054 {
00055 return LogStream;
00056 }
00057
00058 }
00059
00060
00061
00062 void BarryLogf(int verbose, const char *msg, ...)
00063 {
00064 va_list vl;
00065 va_start(vl, msg);
00066 char buffer[2048];
00067 char *output = buffer;
00068 int buflen = sizeof(buffer);
00069 int n = vsnprintf(buffer, buflen, msg, vl);
00070 if( n < 0 || n >= buflen ) {
00071 buflen = n + 100;
00072 output = new char [buflen];
00073 n = vsnprintf(output, buflen, msg, vl);
00074 if( n < 0 || n >= buflen ) {
00075 delete [] output;
00076 output = buffer;
00077 strcpy(buffer, "BarryLog: (trace error, output too long for buffer)");
00078 }
00079 }
00080 va_end(vl);
00081
00082 if( verbose ) {
00083 barryverbose(output);
00084 }
00085 else {
00086 barrylog(output);
00087 }
00088
00089 if( output != buffer )
00090 delete [] output;
00091 }
00092