1 |
//============================================================================ |
2 |
// $Id: Logger.h,v 1.5 2008-03-05 11:36:27 messineo Exp $ |
3 |
// Description : |
4 |
//============================================================================ |
5 |
#ifndef LOGGER_H_ |
6 |
#define LOGGER_H_ |
7 |
|
8 |
#include <string> |
9 |
#include <fstream> |
10 |
#include <sstream> |
11 |
|
12 |
namespace PamOffLineSW{ |
13 |
|
14 |
class LogUtil{ |
15 |
public: |
16 |
enum logLevel{ |
17 |
LOGERROR=0, |
18 |
LOGWARN, |
19 |
LOGINFO, |
20 |
LOGALL |
21 |
}; |
22 |
LogUtil(std::string& filename, logLevel level); |
23 |
LogUtil(std::string& filename); |
24 |
LogUtil(char* filename,logLevel level); |
25 |
LogUtil(char* filename); |
26 |
void setLoglevel(logLevel level); |
27 |
std::string& getLogFileName(); |
28 |
void logError(std::string& msg); |
29 |
void logWarning(std::string& msg); |
30 |
void logInfo(std::string& msg); |
31 |
void logAll(std::string& msg); |
32 |
|
33 |
void logAlways(std::string& msg); |
34 |
void logAlways(char* msg); |
35 |
void logError(char* msg); |
36 |
void logWarning(char* msg); |
37 |
void logInfo(char* msg); |
38 |
void logAll(char* msg); |
39 |
|
40 |
void appendLog(char* msg){mtempstring+=msg;}; |
41 |
void flushLog(logLevel level){ |
42 |
if(level == LOGERROR) logError(mtempstring); |
43 |
if(level == LOGWARN) logError(mtempstring); |
44 |
if(level == LOGINFO) logError(mtempstring); |
45 |
mtempstring+""; |
46 |
}; |
47 |
~LogUtil(); |
48 |
template <class T> |
49 |
std::string value2string(T& val) |
50 |
{ |
51 |
std::ostringstream os; |
52 |
os << val; |
53 |
return os.str(); |
54 |
} |
55 |
private: |
56 |
std::string mFilename; |
57 |
std::ofstream mOutStream; |
58 |
std::string mtempstring; |
59 |
logLevel mLevel; |
60 |
}; |
61 |
|
62 |
class Logger{ |
63 |
public: |
64 |
Logger(); |
65 |
Logger(bool autoflush); //currently not used |
66 |
~Logger(); |
67 |
bool setLogFile(std::string& fileName); |
68 |
bool setLogFile(char* fileName); |
69 |
std::string& getLogFileName(); |
70 |
|
71 |
//TODO: this need to be checked |
72 |
template <class T> |
73 |
bool logValue(T& val) |
74 |
{ |
75 |
mOutStream << val; |
76 |
return checkOutFileStreamError(Logger::LOG_MSG_OPERATION); |
77 |
} |
78 |
|
79 |
bool logENDL(); |
80 |
bool logMsg(std::string&); |
81 |
bool logMsg(char* charstar, int lenght); |
82 |
bool logMsg(char* charstar, long int lenght); |
83 |
//If the charstar buffer is null terminated |
84 |
bool logMsg(char* charstar_nullterminated); |
85 |
|
86 |
bool close(); |
87 |
std::ofstream& getOutStream(); |
88 |
//void setToBeflushedMemorySize(long charCountSize); |
89 |
private: |
90 |
bool checkOutFileStreamError(int operationKind,std::string& optionalMsg); |
91 |
bool checkOutFileStreamError(int operationKind); |
92 |
std::string mFileName; |
93 |
std::string mDummyOptionalMsg; |
94 |
std::string mBlankString; |
95 |
std::string mUnableToOpenFileMsg; |
96 |
std::string mUnableToLogMsg; |
97 |
std::string mToFileMsg; |
98 |
std::string mUnableToCloseMsg; |
99 |
std::string mFileMsg; |
100 |
std::ofstream mOutStream; |
101 |
bool mAutoFlush;//currently not used. it is here for future improvements, if any |
102 |
static const int OPEN_FILE_OPERATION; |
103 |
static const int LOG_MSG_OPERATION; |
104 |
static const int CLOSE_FILE_OPERATION; |
105 |
void initStringMsg(); |
106 |
}; |
107 |
} |
108 |
|
109 |
#endif /*LOGGER_H_*/ |