OpenWalnut  1.5.0dev
WLoggerWrapper.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WLOGGERWRAPPER_H
26 #define WLOGGERWRAPPER_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include <boost/tuple/tuple.hpp>
33 
34 #include "core/common/WLogStream.h"
35 #include "core/common/WLogger.h"
36 
37 /**
38  * \class WLoggerWrapper
39  *
40  * A wrapper for WLogger. This is used to expose a part of the WLogger functionality
41  * to script interpreters.
42  */
44 {
45  /**
46  * A helper class for storing information about file streams that we added to
47  * the logger.
48  */
50  {
51  //! The name of the log file.
52  std::string m_filename;
53 
54  //! The actual stream.
55  std::shared_ptr< std::ofstream > m_fileStream;
56 
57  //! The logstream instance.
59  };
60 
61 public:
62  /**
63  * Constructor. Creates an empty wrapper.
64  */
66 
67  /**
68  * Constructor.
69  *
70  * \param logger A pointer to a logger instance.
71  */
72  explicit WLoggerWrapper( WLogger* logger );
73 
74  /**
75  * Destructor.
76  */
78 
79  /**
80  * Add a file to which the logger output will be written.
81  *
82  * \param filename The name of the file to write logging stuff into.
83  *
84  * \return true, if a stream to that file could be created and added successfully.
85  */
86  bool addFileStream( std::string filename );
87 
88  /**
89  * Remove a file to which the logger writes.
90  *
91  * \param filename The name of the file to remove.
92  *
93  * \return true, if a stream to that file existed and was removed successfully.
94  */
95  bool removeFileStream( std::string filename );
96 
97  /**
98  * Remove all files to which the logger writes (and which were added by this wrapper).
99  */
100  void removeAllFileStreams();
101 
102  /**
103  * Output an error to the logs.
104  *
105  * \param location A string indicating where the error occured.
106  * \param message A message indicating what happened.
107  */
108  void error( std::string const& location, std::string const& message );
109 
110  /**
111  * Output a warning to the logs.
112  *
113  * \param location A string indicating where the problem occured.
114  * \param message A message indicating what happened.
115  */
116  void warning( std::string const& location, std::string const& message );
117 
118  /**
119  * Output information to the logs.
120  *
121  * \param location A string indicating where the info is from.
122  * \param message The information.
123  */
124  void info( std::string const& location, std::string const& message );
125 
126  /**
127  * Output a debug message.
128  *
129  * \param location A string indicating where the message is from.
130  * \param message The debug message.
131  */
132  void debug( std::string const& location, std::string const& message );
133 
134 private:
135  /**
136  * Helper function that removes the file stream with the given index.
137  *
138  * \param i The index of the stream to remove.
139  */
140  void removeFileStreamNumber( size_t i );
141 
142  //! A pointer to the logger.
144 
145  //! List of file streams.
146  std::vector< FileStreamEntry > m_fileStreamList;
147 };
148 
149 #endif // WLOGGERWRAPPER_H
std::shared_ptr< WLogStream > SharedPtr
shared pointer type
Definition: WLogStream.h:41
A wrapper for WLogger.
void warning(std::string const &location, std::string const &message)
Output a warning to the logs.
void debug(std::string const &location, std::string const &message)
Output a debug message.
void removeFileStreamNumber(size_t i)
Helper function that removes the file stream with the given index.
void removeAllFileStreams()
Remove all files to which the logger writes (and which were added by this wrapper).
std::vector< FileStreamEntry > m_fileStreamList
List of file streams.
void error(std::string const &location, std::string const &message)
Output an error to the logs.
WLoggerWrapper()
Constructor.
bool addFileStream(std::string filename)
Add a file to which the logger output will be written.
~WLoggerWrapper()
Destructor.
bool removeFileStream(std::string filename)
Remove a file to which the logger writes.
void info(std::string const &location, std::string const &message)
Output information to the logs.
WLogger * m_logger
A pointer to the logger.
This class defines the interface for adding logs and managing several output streams for them.
Definition: WLogger.h:47
A helper class for storing information about file streams that we added to the logger.
std::string m_filename
The name of the log file.
WLogStream::SharedPtr m_WLogStream
The logstream instance.
std::shared_ptr< std::ofstream > m_fileStream
The actual stream.