All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Logger.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_LOGGING_LOGGER_H_
36 #define _BLAZE_UTIL_LOGGING_LOGGER_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <fstream>
44 #include <boost/thread/mutex.hpp>
46 #include <blaze/util/SystemClock.h>
47 
48 
49 namespace blaze {
50 
51 namespace logging {
52 
53 //=================================================================================================
54 //
55 // CLASS DEFINITION
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
77 class Logger : private Singleton<Logger,SystemClock>
78 {
79  private:
80  //**Constructors********************************************************************************
83  explicit Logger();
85  //**********************************************************************************************
86 
87  public:
88  //**Destructor**********************************************************************************
91  ~Logger();
93  //**********************************************************************************************
94 
95  private:
96  //**Logging functions***************************************************************************
99  template< typename Type > void log( const Type& message );
101  //**********************************************************************************************
102 
103  //**Utility functions***************************************************************************
106  void openLogFile();
108  //**********************************************************************************************
109 
110  //**Member variables****************************************************************************
113  boost::mutex mutex_;
114  std::ofstream log_;
115 
116  //**********************************************************************************************
117 
118  //**Friend declarations*************************************************************************
120  friend class FunctionTrace;
121  friend class LogSection;
124  //**********************************************************************************************
125 };
126 //*************************************************************************************************
127 
128 
129 
130 
131 //=================================================================================================
132 //
133 // LOGGING FUNCTIONS
134 //
135 //=================================================================================================
136 
137 //*************************************************************************************************
146 template< typename Type > // Type of the log message
147 void Logger::log( const Type& message )
148 {
149  boost::mutex::scoped_lock lock( mutex_ );
150  if( !log_.is_open() )
151  openLogFile();
152  log_ << message;
153  log_.flush();
154 }
155 //*************************************************************************************************
156 
157 } // namespace logging
158 
159 } // namespace blaze
160 
161 #endif
RAII object for function tracing.The FunctionTrace class is an auxiliary helper class for the tracing...
Definition: FunctionTrace.h:68
Header file for the SystemClock class.
#define BLAZE_BEFRIEND_SINGLETON
Friendship declaration for the Singleton class template.This macro has to be used in order to declare...
Definition: Singleton.h:447
Logging section for (non-)MPI-parallel environments.The LogSection class is an auxiliary helper class...
Definition: LogSection.h:67
Header file for the Singleton class.
boost::mutex mutex_
Synchronization mutex for thread-parallel logging.
Definition: Logger.h:113
void openLogFile()
Opens and initializes the log file.
Definition: Logger.cpp:144
std::ofstream log_
The log file.
Definition: Logger.h:114
Logger()
Constructor for the Logger class.
Definition: Logger.cpp:77
Base class for all lifetime managed singletons.The Singleton class represents the base class for all ...
Definition: Singleton.h:606
~Logger()
Destructor for the Logger class.
Definition: Logger.cpp:99
Implementation of a logger class.The Logger class represents the core of the logging functionality...
Definition: Logger.h:77
void log(const Type &message)
Writes the log message to the log file.
Definition: Logger.h:147