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

Contents of /smsdaemon/Logger.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 159 - (show annotations) (download)
Mon Dec 8 22:05:16 2008 UTC (15 years, 5 months ago) by torben
File size: 1106 byte(s)
How the f*** do I still forget to add new files  ????
These should be part of r157 : "Move logpart to its own files"


1 #include "Logger.h"
2
3 #include "Common.h"
4 #include <iostream>
5 #include <sstream>
6 #include <fstream>
7 #include <iomanip>
8
9 using namespace std;
10
11 const char* Months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"};
12
13 namespace Logger
14 {
15 string _logFile;
16 void setLogfile(std::string file)
17 {
18 _logFile = file;
19 }
20
21 void logMessage(string msg)
22 {
23 Common* cmn = Common::instance();
24 time_t t = time(0);
25 tm now;
26 localtime_r(&t, &now);
27
28 ostringstream out;
29 out << Months[ now.tm_mon ] << " " << setw(2) << setfill('0') << now.tm_mday;
30 out << " " << setw(2) << setfill('0') << now.tm_hour;
31 out << ":" << setw(2) << setfill('0') << now.tm_min;
32 out << ":" << setw(2) << setfill('0') << now.tm_sec;
33 out << " " << msg << endl;
34
35 if (cmn->isDaemon && _logFile != "" && cmn->daemonized)
36 {
37 seteuid(0);
38 ofstream of( _logFile.c_str(), ios_base::out | ios_base::app | ios_base::ate);//append mode
39 if (of)
40 {
41 of << out.str();
42 of.flush();
43 of.close();
44 }
45 seteuid( cmn->uid);
46 }
47 else
48 {
49 cout << out.str();
50 cout.flush();
51 }
52 }
53 }

  ViewVC Help
Powered by ViewVC 1.1.20