00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mmstools/mmslogger.h"
00034 #include "mmstools/mmsfile.h"
00035 #include "mmstools/tools.h"
00036 #include <stdio.h>
00037
00038 MMSLogger::MMSLogger() {
00039 this->identity = "[UKN]";
00040 this->stdout = false;
00041 }
00042
00043 MMSLogger::MMSLogger(string identity) {
00044 this->identity = "[" + identity + "]";
00045 this->stdout = false;
00046 }
00047
00048 MMSLogger::~MMSLogger() {
00049 }
00050
00051 void MMSLogger::setIdentity(string identity) {
00052 this->identity = "[" + identity + "]";
00053 }
00054
00055 string MMSLogger::getLogfile() {
00056 return this->backend.getLogFile();
00057 }
00058
00059 void MMSLogger::writeLog(string message) {
00060 struct timeval tv;
00061 int num;
00062 char buffer[1280000];
00063 char timebuf[12];
00064
00065 #ifndef MMSLOGGER_STDOUT_ONLY
00066 MMSFile file(this->backend.getLogFile(),MMSFM_APPEND);
00067 #endif
00068
00069 gettimeofday(&tv, NULL);
00070
00071 getCurrentTimeBuffer(NULL, NULL, timebuf, NULL);
00072
00073 num = snprintf( buffer, sizeof(buffer), "%s:%02ld %s: %s\n", timebuf,
00074 tv.tv_usec/10000, this->identity.c_str(), message.c_str() );
00075 #ifdef MMSLOGGER_STDOUT_ONLY
00076 write(fileno(::stdout), buffer, num);
00077 #else
00078 file.writeBuffer(buffer,NULL,1,num);
00079 if(stdout)
00080 printf("%s\n",message.c_str());
00081 #endif
00082 }
00083
00084 void MMSLogger::clearLog() {
00085 #ifndef MMSLOGGER_STDOUT_ONLY
00086 MMSFile file(this->backend.getLogFile(),MMSFM_WRITE);
00087 #endif
00088 }
00089
00090 void MMSLogger::setStdout(bool writestdout) {
00091 this->stdout=writestdout;
00092 }