opensurgsim
Logger.h
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_LOGGER_H
17 #define SURGSIM_FRAMEWORK_LOGGER_H
18 
19 #include "SurgSim/Framework/LoggerManager.h"
20 #include "SurgSim/Framework/LogOutput.h"
21 
22 #include <string>
23 #include <memory>
24 
25 namespace SurgSim
26 {
27 namespace Framework
28 {
29 
32 
37 {
48 };
49 
51 class Logger
52 {
53 public:
54 
55  friend class LoggerManager;
56 
59  {
60  }
61 
65  bool writeMessage(const std::string& message)
66  {
67  return m_output->writeMessage(message);
68  }
69 
73  int getThreshold() const
74  {
75  return m_threshold;
76  }
77 
81  void setThreshold(int val)
82  {
83  m_threshold = val;
84  }
85 
88  std::shared_ptr<LogOutput> getOutput() const
89  {
90  return m_output;
91  }
92 
95  void setOutput(std::shared_ptr<LogOutput> val)
96  {
97  m_output = val;
98  }
99 
102  std::string getName( ) const
103  {
104  return m_name;
105  }
106 
109  static std::shared_ptr<Logger> getLogger(const std::string& name)
110  {
111  return getLoggerManager()->getLogger(name);
112  }
113 
116  static std::shared_ptr<Logger> getDefaultLogger()
117  {
118  return getLoggerManager()->getDefaultLogger();
119  }
120 
123  static std::shared_ptr<LoggerManager> getLoggerManager();
124 
125 private:
129  Logger(const std::string& name, std::shared_ptr<LogOutput> output);
130 
131  int m_threshold;
132  std::string m_name;
133  std::shared_ptr<LogOutput> m_output;
134 };
135 
136 
138 
139 }; // namespace Framework
140 }; // namespace SurgSim
141 
142 #endif // SURGSIM_FRAMEWORK_LOGGER_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
LogLevel
Logging levels.
Definition: Logger.h:36
void setOutput(std::shared_ptr< LogOutput > val)
Sets the output object used by this logger.
Definition: Logger.h:95
int getThreshold() const
Gets the logging threshold.
Definition: Logger.h:73
Something failed and will impact functionality, some parts of the program will not function correctly...
Definition: Logger.h:45
std::string getName() const
Gets this logger&#39;s name.
Definition: Logger.h:102
void setThreshold(int val)
Sets the logging threshold.
Definition: Logger.h:81
An object that can be used to control logging parameters, such as verbosity and log output destinatio...
Definition: Logger.h:51
bool writeMessage(const std::string &message)
Uses the contained instance of LogOutput to write the log message.
Definition: Logger.h:65
Use at your discretion.
Definition: Logger.h:39
static std::shared_ptr< LoggerManager > getLoggerManager()
Get the logger manager.
Definition: Logger.cpp:30
Something failed, but the impact of the failure is not know or minimal (e.g. purely visual)...
Definition: Logger.h:43
Used by assertion, after using this level the program will not be functional at all.
Definition: Logger.h:47
std::shared_ptr< LogOutput > getOutput() const
Gets the output object used by this logger.
Definition: Logger.h:88
static std::shared_ptr< Logger > getLogger(const std::string &name)
Get a logger by name from Logger Manager.
Definition: Logger.h:109
Class to safely handle access to a group of loggers, manipulate the global logging threshold...
Definition: LoggerManager.h:33
static std::shared_ptr< Logger > getDefaultLogger()
Get default logger.
Definition: Logger.h:116
~Logger()
Destructor.
Definition: Logger.h:58
Informational, notify of state changes.
Definition: Logger.h:41