LoggerManager.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_LOGGERMANAGER_H
17 #define SURGSIM_FRAMEWORK_LOGGERMANAGER_H
18 
19 #include <unordered_map>
20 #include <boost/thread/mutex.hpp>
21 
22 namespace SurgSim
23 {
24 namespace Framework
25 {
26 
27 class Logger;
28 class LogOutput;
29 
33 {
34 public:
36  LoggerManager();
37 
40 
43  void setDefaultOutput(std::shared_ptr<LogOutput> output);
44 
46  std::shared_ptr<LogOutput> getDefaultOutput() const;
47 
50  std::shared_ptr<Logger> getDefaultLogger();
51 
56  std::shared_ptr<Logger> getLogger(const std::string& name);
57 
60  void setThreshold(int threshold);
61 
66  void setThreshold(const std::string& path, int threshold);
67 
70  int getThreshold() const;
71 
72 private:
74  std::unordered_map<std::string, std::shared_ptr<Logger>> m_loggers;
75 
77  std::shared_ptr<LogOutput> m_defaultOutput;
78 
81 
82  boost::mutex m_mutex;
83 
84  // Aug 13, 2013
85  // VS2012 does not support "delete" now
88 };
89 
90 }; // Framework
91 }; // SurgSim
92 
93 #endif //SURGSIM_FRAMEWORK_LOGGERMANAGER_H
Definition: DriveElementFromInputBehavior.cpp:27
std::unordered_map< std::string, std::shared_ptr< Logger > > m_loggers
Keep track of all the loggers.
Definition: LoggerManager.h:74
int m_globalThreshold
Threshold used by all loggers.
Definition: LoggerManager.h:80
~LoggerManager()
Destructor.
Definition: LoggerManager.cpp:38
std::shared_ptr< LogOutput > getDefaultOutput() const
Return the default output.
Definition: LoggerManager.cpp:48
boost::mutex m_mutex
Definition: LoggerManager.h:82
std::shared_ptr< LogOutput > m_defaultOutput
Use for default output of the logger.
Definition: LoggerManager.h:77
void setThreshold(int threshold)
Sets a threshold for all loggers.
Definition: LoggerManager.cpp:54
std::shared_ptr< Logger > getLogger(const std::string &name)
Gets a logger with a given name, creates a new one if none exists or the logger has been deallocated...
Definition: LoggerManager.cpp:84
int getThreshold() const
Return the threshold used by all loggers.
Definition: LoggerManager.cpp:78
void setDefaultOutput(std::shared_ptr< LogOutput > output)
Sets/Changes default output.
Definition: LoggerManager.cpp:43
LoggerManager()
Constructor.
Definition: LoggerManager.cpp:30
std::shared_ptr< Logger > getDefaultLogger()
Gets the default logger.
Definition: LoggerManager.cpp:105
Class to safely handle access to a group of loggers, manipulate the global logging threshold...
Definition: LoggerManager.h:32
LoggerManager & operator=(const LoggerManager &)