log.cc
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 int n = vsnprintf(buffer, sizeof(buffer), msg, vl);
00068 va_end(vl);
00069 if( n > -1 && n < (int)sizeof(buffer) )
00070 strcpy(buffer, "BarryLog: (trace error, output too long for buffer)");
00071
00072 if( verbose ) {
00073 barryverbose(buffer);
00074 }
00075 else {
00076 barrylog(buffer);
00077 }
00078 }
00079