xmscore  1.0
XmLog.h
Go to the documentation of this file.
1 #pragma once
2 //------------------------------------------------------------------------------
8 //------------------------------------------------------------------------------
9 
10 //----- Included files ---------------------------------------------------------
11 // 1. Standard library headers
12 
13 // 3. Standard Library Headers
14 #include <vector>
15 
16 // 4. External Library Headers
17 #include <boost/function.hpp>
18 #include <boost/scoped_ptr.hpp>
19 
20 // 5. Shared Headers
21 #include <xmscore/misc/Singleton.h>
22 
23 // 6. Non-shared Headers
24 
25 //----- Defines ----------------------------------------------------------------
26 
27 //------------------------------------------------------------------------------
32 //------------------------------------------------------------------------------
33 #if _WIN32 || _WIN64 // WIN
34 // An odd ball string expansion requirement for the preprocessor
35 #define XM_UTIL2(line) UTIL##line
36 #define XM_UTIL(line) XM_UTIL2(line)
37 #define XM_LOG(A, B) \
38  ::xms::XmLog::Instance().Log(__FILE__, __LINE__, A, B); \
39  \
40 static std::string XM_UTIL(__LINE__); \
41  \
42 if(XM_UTIL(__LINE__).empty()) \
43  { \
44  XM_UTIL(__LINE__) = xms::g_xmUtil; \
45  \
46 }
47 
48 namespace xms
49 {
50 //------------------------------------------------------------------------------
52 //------------------------------------------------------------------------------
53 extern std::string g_xmUtil;
54 }
55 #else // NOT WIN
56 #define XM_LOG(A, B) ::xms::XmLog::Instance().Log(__FILE__, __LINE__, A, B);
57 #endif // NOT WIN
58 
59 //----- Forward declarations ---------------------------------------------------
60 
61 //----- Namespace declaration --------------------------------------------------
62 
63 //----- Constants / Enumerations -----------------------------------------------
64 
65 // Define Severity Levels
66 
73 
75 namespace xmlog
76 {
79  info,
83 };
84 /*
85 //------------------------------------------------------------------------------
87 //------------------------------------------------------------------------------
88 static std::string MessageTypeStr(MessageTypeEnum a_level) {
89  if (a_level == info) return "INFO";
90  if (a_level == warning) return "WARNING";
91  if (a_level == error) return "ERROR";
92  if (a_level == debug) return "DEBUG";
93  return "";
94 } // MessageTypeStr
95 */
96 }
97 
98 namespace xms
99 {
101 typedef boost::function<std::string()> XmLogFilenameCallback;
102 
104 typedef std::vector<std::pair<xmlog::MessageTypeEnum, std::string>> MessageStack;
105 
106 //----- Structs / Classes ------------------------------------------------------
107 
112 class XmLog : public xms::Singleton<XmLog>
113 {
116 
117 public:
118  ~XmLog();
119  void Log(const char* const a_file,
120  int a_line,
121  xmlog::MessageTypeEnum a_level,
122  std::string a_message);
123  int ErrCount();
124  MessageStack GetAndClearStack();
125  std::string GetAndClearStackStr();
126  static XmLogFilenameCallback& LogFilenameCallback();
127  static std::string LogFilename();
128 
129 private:
131  XmLog();
132  struct Impl;
134  boost::scoped_ptr<Impl> m;
135 }; // class XmLog
136 
137 //----- Global functions -------------------------------------------------------
138 
139 } // namespace xms
std::vector< std::pair< xmlog::MessageTypeEnum, std::string > > MessageStack
Container type used to store log messages.
Definition: XmLog.h:104
Warning message for the user.
Definition: XmLog.h:80
Details of internal operation.
Definition: XmLog.h:82
MessageTypeEnum
Log level for XM_LOG.
Definition: XmLog.h:78
Base class for classes that follow the singleton pattern.
Definition: Singleton.h:26
boost::scoped_ptr< Impl > m
Implementation pointer.
Definition: XmLog.h:132
Definition: XmLog.cpp:67
boost::function< std::string()> XmLogFilenameCallback
Callback to return the name of the log file.
Definition: XmLog.h:101
implementation of XmLog
Definition: XmLog.cpp:113
Informational message for the user.
Definition: XmLog.h:79
Critical error message for the user.
Definition: XmLog.h:81