LogOutput.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_FRAMEWORK_LOGOUTPUT_H
17 #define SURGSIM_FRAMEWORK_LOGOUTPUT_H
18 
19 #include <fstream>
20 #include <boost/thread/mutex.hpp>
21 
22 namespace SurgSim
23 {
24 namespace Framework
25 {
26 
28 class LogOutput
29 {
30 public:
32  {
33  }
34 
35  virtual ~LogOutput()
36  {
37  }
38 
41  virtual bool writeMessage(const std::string& message) = 0;
42 
43 };
44 
45 class NullOutput : public LogOutput
46 {
47 public:
48  virtual bool writeMessage(const std::string& message) {return true;}
49 };
50 
51 
53 class FileOutput : public LogOutput
54 {
55 public:
56 
59  explicit FileOutput(const std::string& filename);
60 
61  virtual ~FileOutput();
62 
65  virtual bool writeMessage(const std::string& message) override;
66 
67 private:
68  std::string m_filename;
69  std::ofstream m_stream;
70  boost::mutex m_mutex;
71 };
72 
75 class StreamOutput : public LogOutput
76 {
77 public:
78 
82  explicit StreamOutput(std::ostream& ostream); //NOLINT
83  virtual ~StreamOutput();
84 
88  virtual bool writeMessage(const std::string& message) override;
89 
90 private:
91  std::ostream& m_stream;
92  boost::mutex m_mutex;
93 };
94 
95 }; // namespace Framework
96 }; // namespace SurgSim
97 
98 #endif // SURGSIM_FRAMEWORK_LOGOUTPUT_H
StreamOutput(std::ostream &ostream)
Constructor.
Definition: LogOutput.cpp:57
Definition: DriveElementFromInputBehavior.cpp:27
virtual ~StreamOutput()
Definition: LogOutput.cpp:61
Virtual Base class to define an interface for outputting logging information.
Definition: LogOutput.h:28
virtual ~FileOutput()
Definition: LogOutput.cpp:40
std::ostream & m_stream
Definition: LogOutput.h:91
virtual bool writeMessage(const std::string &message) override
Writes a message to the stream.
Definition: LogOutput.cpp:70
std::ofstream m_stream
Definition: LogOutput.h:69
LogOutput()
Definition: LogOutput.h:31
virtual ~LogOutput()
Definition: LogOutput.h:35
virtual bool writeMessage(const std::string &message) override
Definition: LogOutput.cpp:45
Definition: LogOutput.h:45
boost::mutex m_mutex
Definition: LogOutput.h:70
Class to output logging information to a give file.
Definition: LogOutput.h:53
Class to output logging information to a stream that can be passed into the constructor of the class...
Definition: LogOutput.h:75
std::string m_filename
Definition: LogOutput.h:68
FileOutput(const std::string &filename)
Constructor.
Definition: LogOutput.cpp:29
boost::mutex m_mutex
Definition: LogOutput.h:92
virtual bool writeMessage(const std::string &message)
Definition: LogOutput.h:48
virtual bool writeMessage(const std::string &message)=0