/[projects]/smsdaemon/common.cpp
ViewVC logotype

Diff of /smsdaemon/common.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 156 by torben, Sun Dec 7 21:42:15 2008 UTC revision 157 by torben, Mon Dec 8 21:28:40 2008 UTC
# Line 7  Line 7 
7  #include <string>  #include <string>
8  #include <iostream>  #include <iostream>
9  #include <iomanip>  #include <iomanip>
 #include <fstream>  
10  #include <sstream>  #include <sstream>
11  #include <time.h>  #include <time.h>
12    
# Line 16  Line 15 
15  #include "ConfigFile.h"  #include "ConfigFile.h"
16    
17  using namespace std;  using namespace std;
 const char* Months[] = {  "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"};  
18    
19  Common* Common::instance()  Common* Common::instance()
20  {  {
# Line 61  ConfigFile* Common::GetConfigfile() Line 59  ConfigFile* Common::GetConfigfile()
59          return _configFile;          return _configFile;
60  }  }
61    
 void Common::logMessage(string msg)  
 {        
         time_t t = time(0);  
         tm now;  
         localtime_r(&t, &now);  
   
         ostringstream out;  
         out << Months[ now.tm_mon ] << " " << setw(2) << setfill('0') << now.tm_mday;  
         out << " " << setw(2) << setfill('0') << now.tm_hour;  
         out << ":" << setw(2) << setfill('0') << now.tm_min;  
         out << ":" << setw(2) << setfill('0') << now.tm_sec;  
         out << "  " << msg << endl;  
   
         if (this->isDaemon && _logFile != "" && daemonized)  
         {  
                 seteuid(0);  
                 ofstream of( _logFile.c_str(), ios_base::out | ios_base::app | ios_base::ate);//append mode  
                 if (of)  
                 {  
                         of << out.str();  
                         of.flush();  
                         of.close();  
                 }  
                 seteuid( this->uid);  
         }  
         else  
         {  
                 cout << out.str();  
                 cout.flush();  
         }  
 }  
62    
63  void Common::printUsage()  void Common::printUsage()
64  {  {

Legend:
Removed from v.156  
changed lines
  Added in v.157

  ViewVC Help
Powered by ViewVC 1.1.20