opensurgsim
LogOutput.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2016, 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 <boost/thread/mutex.hpp>
20 #include <fstream>
21 
22 namespace SurgSim
23 {
24 namespace Framework
25 {
26 
28 class LogOutput
29 {
30 public:
31  LogOutput()
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 
63  bool writeMessage(const std::string& message) override;
64 
65 private:
66  std::string m_filename;
67  std::ofstream m_stream;
68  boost::mutex m_mutex;
69 };
70 
73 class StreamOutput : public LogOutput
74 {
75 public:
76 
80  explicit StreamOutput(std::ostream& ostream); //NOLINT
81 
85  bool writeMessage(const std::string& message) override;
86 
87 private:
88  std::ostream& m_stream;
89  boost::mutex m_mutex;
90 };
91 
92 }; // namespace Framework
93 }; // namespace SurgSim
94 
95 #endif // SURGSIM_FRAMEWORK_LOGOUTPUT_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Virtual Base class to define an interface for outputting logging information.
Definition: LogOutput.h:28
Definition: LogOutput.h:45
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:73
virtual bool writeMessage(const std::string &message)
Definition: LogOutput.h:48
virtual bool writeMessage(const std::string &message)=0