/[PAMELA software]/chewbacca/PamOffLineSW/Logger.h
ViewVC logotype

Annotation of /chewbacca/PamOffLineSW/Logger.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed Aug 5 18:48:42 2009 UTC (15 years, 4 months ago) by pam-fi
Branch: MAIN
CVS Tags: v10RED, v9r00, v9r01, HEAD
Changes since 1.1: +9 -9 lines
File MIME type: text/plain
Various minor modifications for compatibility with gcc 4.4, removal of warnings due to mismatch between char* and const char*, bug fix.

1 mocchiut 1.1 //============================================================================
2 pam-fi 1.2 // $Id: Logger.h,v 1.1.1.1 2008-09-23 07:20:11 mocchiut Exp $
3 mocchiut 1.1 // 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 pam-fi 1.2 LogUtil(const char* filename,logLevel level);
25     LogUtil(const char* filename);
26 mocchiut 1.1 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 pam-fi 1.2 void logAlways(const char* msg);
35     void logError(const char* msg);
36     void logWarning(const char* msg);
37     void logInfo(const char* msg);
38     void logAll(const char* msg);
39 mocchiut 1.1
40 pam-fi 1.2 void appendLog(const char* msg){mtempstring+=msg;};
41 mocchiut 1.1 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_*/

  ViewVC Help
Powered by ViewVC 1.1.23