Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmslogger.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
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 }

Generated by doxygen