LogMessageBase.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_LOGMESSAGEBASE_H
#define SURGSIM_FRAMEWORK_LOGMESSAGEBASE_H
#include <string>
#include <sstream>
#include <iomanip>
#include <ctime>
#include "SurgSim/Framework/Logger.h"
namespace SurgSim
{
namespace Framework
{
class LogMessageBase
{
public:
LogMessageBase(Logger* logger, int level);
~LogMessageBase()
{
}
template <typename T>
LogMessageBase& operator <<(T&& input)
{
m_stream << input;
return *this;
}
// A specialization for output manipulators (functions that apply to the stream).
// Otherwise overloaded manipulators like std::endl and std::endl don't work, since the compiler can't know
// what overloaded variant to apply.
LogMessageBase& operator <<(std::ios_base& (*manipulator)(std::ios_base&))
{
m_stream << *manipulator;
return *this;
}
// A specialization for output manipulators (functions that apply to the stream).
// Otherwise overloaded manipulators like std::hex and std::endl don't work, since the compiler can't know
// what overloaded variant to apply.
LogMessageBase& operator <<(std::ostream& (*manipulator)(std::ostream&))
{
m_stream << *manipulator;
return *this;
}
protected:
std::string getMessage()
{
return m_stream.str();
}
void flush()
{
m_logger->writeMessage(m_stream.str());
}
private:
std::ostringstream m_stream;
Logger* m_logger;
};
}; // namespace Framework
}; // namespace SurgSim
#endif // SURGSIM_FRAMEWORK_LOGMESSAGEBASE_H
SurgSim::Framework::LogMessageBase::LogMessageBase
LogMessageBase(Logger *logger, int level)
Construct a LogMessage.
Definition: LogMessageBase.cpp:25
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Framework::LogMessageBase::m_logger
Logger * m_logger
Definition: LogMessageBase.h:96
SurgSim::Framework::LogMessageBase::~LogMessageBase
~LogMessageBase()
Destructor.
Definition: LogMessageBase.h:50
SurgSim::Framework::LogMessageBase::flush
void flush()
write the current message to the logger
Definition: LogMessageBase.h:89
SurgSim::Framework::LogMessageBase::m_stream
std::ostringstream m_stream
Definition: LogMessageBase.h:95
SurgSim::Framework::LogMessageBase::operator<<
LogMessageBase & operator<<(T &&input)
Add the given input to the current log message.
Definition: LogMessageBase.h:57
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
Logger.h
SurgSim::Framework::LogMessageBase::getMessage
std::string getMessage()
Definition: LogMessageBase.h:83
SurgSim::Framework::LogMessageBase
LogMessageBase is a base class to be used to customize messages for logging textual information can b...
Definition: LogMessageBase.h:40