OpenWalnut  1.4.0
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 <string>
29 #include <vector>
30 
31 #include <boost/shared_ptr.hpp>
32 #include <boost/tuple/tuple.hpp>
33 
34 
35 #include "core/common/WLogger.h"
36 #include "core/common/WLogStream.h"
37 
38 /**
39  * \class WLoggerWrapper
40  *
41  * A wrapper for WLogger. This is used to expose a part of the WLogger functionality
42  * to script interpreters.
43  */
45 {
46  /**
47  * A helper class for storing information about file streams that we added to
48  * the logger.
49  */
51  {
52  //! The name of the log file.
53  std::string m_filename;
54 
55  //! The actual stream.
56  boost::shared_ptr< std::ofstream > m_fileStream;
57 
58  //! The logstream instance.
60  };
61 
62 public:
63  /**
64  * Constructor. Creates an empty wrapper.
65  */
67 
68  /**
69  * Constructor.
70  *
71  * \param logger A pointer to a logger instance.
72  */
73  explicit WLoggerWrapper( WLogger* logger );
74 
75  /**
76  * Destructor.
77  */
79 
80  /**
81  * Add a file to which the logger output will be written.
82  *
83  * \param filename The name of the file to write logging stuff into.
84  *
85  * \return true, if a stream to that file could be created and added successfully.
86  */
87  bool addFileStream( std::string filename );
88 
89  /**
90  * Remove a file to which the logger writes.
91  *
92  * \param filename The name of the file to remove.
93  *
94  * \return true, if a stream to that file existed and was removed successfully.
95  */
96  bool removeFileStream( std::string filename );
97 
98  /**
99  * Remove all files to which the logger writes (and which were added by this wrapper).
100  */
101  void removeAllFileStreams();
102 
103 private:
104  /**
105  * Helper function that removes the file stream with the given index.
106  *
107  * \param i The index of the stream to remove.
108  */
109  void removeFileStreamNumber( size_t i );
110 
111  //! A pointer to the logger.
113 
114  //! List of file streams.
115  std::vector< FileStreamEntry > m_fileStreamList;
116 };
117 
118 #endif // WLOGGERWRAPPER_H
std::string m_filename
The name of the log file.
WLogStream::SharedPtr m_WLogStream
The logstream instance.
void removeFileStreamNumber(size_t i)
Helper function that removes the file stream with the given index.
A wrapper for WLogger.
This class defines the interface for adding logs and managing several output streams for them...
Definition: WLogger.h:46
WLogger * m_logger
A pointer to the logger.
bool removeFileStream(std::string filename)
Remove a file to which the logger writes.
~WLoggerWrapper()
Destructor.
boost::shared_ptr< std::ofstream > m_fileStream
The actual stream.
WLoggerWrapper()
Constructor.
boost::shared_ptr< WLogStream > SharedPtr
shared pointer type
Definition: WLogStream.h:40
std::vector< FileStreamEntry > m_fileStreamList
List of file streams.
A helper class for storing information about file streams that we added to the logger.
void removeAllFileStreams()
Remove all files to which the logger writes (and which were added by this wrapper).
bool addFileStream(std::string filename)
Add a file to which the logger output will be written.