All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Logger.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_UTIL_LOGGING_LOGGER_H_
23 #define _BLAZE_UTIL_LOGGING_LOGGER_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <fstream>
31 #include <boost/thread/mutex.hpp>
33 #include <blaze/util/SystemClock.h>
34 
35 
36 namespace blaze {
37 
38 namespace logging {
39 
40 //=================================================================================================
41 //
42 // CLASS DEFINITION
43 //
44 //=================================================================================================
45 
46 //*************************************************************************************************
64 class Logger : private Singleton<Logger,SystemClock>
65 {
66  private:
67  //**Constructors********************************************************************************
70  explicit Logger();
72  //**********************************************************************************************
73 
74  public:
75  //**Destructor**********************************************************************************
78  ~Logger();
80  //**********************************************************************************************
81 
82  private:
83  //**Logging functions***************************************************************************
86  template< typename Type > void log( const Type& message );
88  //**********************************************************************************************
89 
90  //**Utility functions***************************************************************************
93  void openLogFile();
95  //**********************************************************************************************
96 
97  //**Member variables****************************************************************************
100  boost::mutex mutex_;
101  std::ofstream log_;
102 
103  //**********************************************************************************************
104 
105  //**Friend declarations*************************************************************************
107  friend class LogSection;
110  //**********************************************************************************************
111 };
112 //*************************************************************************************************
113 
114 
115 
116 
117 //=================================================================================================
118 //
119 // LOGGING FUNCTIONS
120 //
121 //=================================================================================================
122 
123 //*************************************************************************************************
132 template< typename Type > // Type of the log message
133 void Logger::log( const Type& message )
134 {
135  boost::mutex::scoped_lock lock( mutex_ );
136  if( !log_.is_open() )
137  openLogFile();
138  log_ << message;
139  log_.flush();
140 }
141 //*************************************************************************************************
142 
143 } // namespace logging
144 
145 } // namespace blaze
146 
147 #endif