Logger.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_LOGGER_H
17 #define SURGSIM_FRAMEWORK_LOGGER_H
18 
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 
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
SurgSim::Framework::Logger::~Logger
~Logger()
Destructor.
Definition: Logger.h:58
SurgSim::Framework::Logger::getLogger
static std::shared_ptr< Logger > getLogger(const std::string &name)
Get a logger by name from Logger Manager.
Definition: Logger.h:109
LoggerManager.h
SurgSim::Framework::LoggerManager
Class to safely handle access to a group of loggers, manipulate the global logging threshold,...
Definition: LoggerManager.h:33
SurgSim::Framework::Logger::m_threshold
int m_threshold
Definition: Logger.h:131
SurgSim::Framework::LOG_LEVEL_INFO
Informational, notify of state changes.
Definition: Logger.h:41
SurgSim::Framework::Logger::Logger
Logger(const std::string &name, std::shared_ptr< LogOutput > output)
Constructor.
Definition: Logger.cpp:23
SurgSim::Framework::Logger::m_output
std::shared_ptr< LogOutput > m_output
Definition: Logger.h:133
SurgSim::Framework::Logger::writeMessage
bool writeMessage(const std::string &message)
Uses the contained instance of LogOutput to write the log message.
Definition: Logger.h:65
LogOutput.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Framework::Logger::getLoggerManager
static std::shared_ptr< LoggerManager > getLoggerManager()
Get the logger manager.
Definition: Logger.cpp:30
SurgSim::Framework::LOG_LEVEL_CRITICAL
Used by assertion, after using this level the program will not be functional at all.
Definition: Logger.h:47
SurgSim::Framework::Logger::getDefaultLogger
static std::shared_ptr< Logger > getDefaultLogger()
Get default logger.
Definition: Logger.h:116
SurgSim::Framework::LOG_LEVEL_SEVERE
Something failed and will impact functionality, some parts of the program will not function correctly...
Definition: Logger.h:45
SurgSim::Framework::Logger::getName
std::string getName() const
Gets this logger's name.
Definition: Logger.h:102
SurgSim::Framework::Logger::setOutput
void setOutput(std::shared_ptr< LogOutput > val)
Sets the output object used by this logger.
Definition: Logger.h:95
SurgSim::Framework::Logger::m_name
std::string m_name
Definition: Logger.h:132
SurgSim::Framework::Logger::getThreshold
int getThreshold() const
Gets the logging threshold.
Definition: Logger.h:73
SurgSim::Framework::Logger::setThreshold
void setThreshold(int val)
Sets the logging threshold.
Definition: Logger.h:81
SurgSim::Framework::Logger::getOutput
std::shared_ptr< LogOutput > getOutput() const
Gets the output object used by this logger.
Definition: Logger.h:88
SurgSim::Framework::LOG_LEVEL_DEBUG
Use at your discretion.
Definition: Logger.h:39
SurgSim::Framework::LOG_LEVEL_WARNING
Something failed, but the impact of the failure is not know or minimal (e.g. purely visual).
Definition: Logger.h:43
SurgSim::Framework::Logger
An object that can be used to control logging parameters, such as verbosity and log output destinatio...
Definition: Logger.h:51
SurgSim::Framework::LogLevel
LogLevel
Logging levels.
Definition: Logger.h:36