Logger.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_FRAMEWORK_LOGGER_H
#define SURGSIM_FRAMEWORK_LOGGER_H
#include "SurgSim/Framework/LoggerManager.h"
#include "SurgSim/Framework/LogOutput.h"
#include <string>
#include <memory>
namespace SurgSim
{
namespace Framework
{
enum LogLevel
{
LOG_LEVEL_DEBUG,
LOG_LEVEL_INFO,
LOG_LEVEL_WARNING,
LOG_LEVEL_SEVERE,
LOG_LEVEL_CRITICAL
};
class Logger
{
public:
friend class LoggerManager;
~Logger()
{
}
bool writeMessage(const std::string& message)
{
return m_output->writeMessage(message);
}
int getThreshold() const
{
return m_threshold;
}
void setThreshold(int val)
{
m_threshold = val;
}
std::shared_ptr<LogOutput> getOutput() const
{
return m_output;
}
void setOutput(std::shared_ptr<LogOutput> val)
{
m_output = val;
}
std::string getName( ) const
{
return m_name;
}
static std::shared_ptr<Logger> getLogger(const std::string& name)
{
return getLoggerManager()->getLogger(name);
}
static std::shared_ptr<Logger> getDefaultLogger()
{
return getLoggerManager()->getDefaultLogger();
}
static std::shared_ptr<LoggerManager> getLoggerManager();
private:
Logger(const std::string& name, std::shared_ptr<LogOutput> output);
int m_threshold;
std::string m_name;
std::shared_ptr<LogOutput> m_output;
};
}; // namespace Framework
}; // namespace SurgSim
#endif // SURGSIM_FRAMEWORK_LOGGER_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Framework::LogLevel
LogLevel
Logging levels.
Definition: Logger.h:36
SurgSim::Framework::Logger::m_output
std::shared_ptr< LogOutput > m_output
Definition: Logger.h:133
SurgSim::Framework::Logger::setOutput
void setOutput(std::shared_ptr< LogOutput > val)
Sets the output object used by this logger.
Definition: Logger.h:95
LoggerManager.h
SurgSim::Framework::Logger::getThreshold
int getThreshold() const
Gets the logging threshold.
Definition: Logger.h:73
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::m_threshold
int m_threshold
Definition: Logger.h:131
SurgSim::Framework::Logger::getName
std::string getName() const
Gets this logger&#39;s name.
Definition: Logger.h:102
SurgSim::Framework::Logger::setThreshold
void setThreshold(int val)
Sets the logging threshold.
Definition: Logger.h:81
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::Logger::writeMessage
bool writeMessage(const std::string &message)
Uses the contained instance of LogOutput to write the log message.
Definition: Logger.h:65
SurgSim::Framework::LOG_LEVEL_DEBUG
Use at your discretion.
Definition: Logger.h:39
SurgSim::Framework::Logger::getLoggerManager
static std::shared_ptr< LoggerManager > getLoggerManager()
Get the logger manager.
Definition: Logger.cpp:30
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
LogOutput.h
SurgSim::Framework::Logger::m_name
std::string m_name
Definition: Logger.h:132
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::getOutput
std::shared_ptr< LogOutput > getOutput() const
Gets the output object used by this logger.
Definition: Logger.h:88
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
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::getDefaultLogger
static std::shared_ptr< Logger > getDefaultLogger()
Get default logger.
Definition: Logger.h:116
SurgSim::Framework::Logger::~Logger
~Logger()
Destructor.
Definition: Logger.h:58
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