##

Console.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* 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 _GAZEBO_CONSOLE_HH_
#define _GAZEBO_CONSOLE_HH_
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829
# include <boost/thread.hpp>
#endif
#include "gazebo/common/SingletonT.hh"
#include "gazebo/common/CommonTypes.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace common
{
#define gzmsg (gazebo::common::Console::msg())
#define gzdbg (gazebo::common::Console::dbg(__FILE__, __LINE__))
#define gzwarn (gazebo::common::Console::warn(__FILE__, __LINE__))
#define gzerr (gazebo::common::Console::err(__FILE__, __LINE__))
#define gzlog (gazebo::common::Console::log())
#define gzLogInit(_prefix, _str) \
(gazebo::common::Console::log.Init(_prefix, _str))
#define gzLogDirectory() (gazebo::common::Console::log.GetLogDirectory())
class GZ_COMMON_VISIBLE FileLogger : public std::ostream
{
public: explicit FileLogger(const std::string &_filename = "");
public: virtual ~FileLogger();
public: void Init(const std::string &_prefix,
const std::string &_filename);
public: virtual FileLogger &operator()();
public: virtual FileLogger &operator()(
const std::string &_file, int _line);
public: std::string GetLogDirectory() const;
private: static std::string GetMasterPort();
protected: class Buffer : public std::stringbuf
{
public: explicit Buffer(const std::string &_filename);
public: virtual ~Buffer();
public: virtual int sync();
public: std::ofstream *stream;
};
private: std::string logDirectory;
};
class GZ_COMMON_VISIBLE Logger : public std::ostream
{
public: enum LogType
{
STDOUT,
STDERR
};
public: Logger(const std::string &_prefix, int _color, LogType _type);
public: virtual ~Logger();
public: virtual Logger &operator()();
public: virtual Logger &operator()(
const std::string &_file, int _line);
protected: class Buffer : public std::stringbuf
{
public: Buffer(LogType _type, int _color);
public: virtual ~Buffer();
public: virtual int sync();
public: LogType type;
public: int color;
};
public: int color;
private: std::string prefix;
};
class GZ_COMMON_VISIBLE Console
{
public: static void SetQuiet(bool _q);
public: static bool GetQuiet();
public: static Logger msg;
public: static Logger err;
public: static Logger dbg;
public: static Logger warn;
public: static FileLogger log;
private: static bool quiet;
};
}
}
#endif
gazebo::common::Console::dbg
static Logger dbg
Global instance of the debug logger.
Definition: Console.hh:222
gazebo::common::Logger::Logger
Logger(const std::string &_prefix, int _color, LogType _type)
Constructor.
gazebo::common::FileLogger::GetLogDirectory
std::string GetLogDirectory() const
Get the full path of the directory where all the log files are stored.
gazebo::common::Logger::LogType
LogType
Output destination type.
Definition: Console.hh:140
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::common::Logger::STDOUT
Output to stdout.
Definition: Console.hh:143
gazebo::common::Logger::Buffer::Buffer
Buffer(LogType _type, int _color)
Constructor.
common
common
Definition: FuelModelDatabase.hh:37
gazebo::common::Console::msg
static Logger msg
Global instance of the message logger.
Definition: Console.hh:216
gazebo::common::Logger::color
int color
Color for the output.
Definition: Console.hh:196
gazebo::common::Logger::Buffer::color
int color
ANSI color code using Select Graphic Rendition parameters (SGR).
Definition: Console.hh:192
system.hh
CommonTypes.hh
gazebo::common::FileLogger::Buffer::sync
virtual int sync()
Sync the stream (output the string buffer contents).
gazebo::common::FileLogger::Buffer::Buffer
Buffer(const std::string &_filename)
Constructor.
gazebo::common::Logger::Buffer::~Buffer
virtual ~Buffer()
Destructor.
gazebo::common::Logger::~Logger
virtual ~Logger()
Destructor.
gazebo::common::Logger::Buffer::type
LogType type
Destination type for the messages.
Definition: Console.hh:187
gazebo::common::FileLogger::Buffer
String buffer for the file logger.
Definition: Console.hh:111
gazebo::common::Console::SetQuiet
static void SetQuiet(bool _q)
Set quiet output.
gazebo::common::FileLogger::Init
void Init(const std::string &_prefix, const std::string &_filename)
Initialize the file logger.
gazebo::common::Logger
Terminal logger.
Definition: Console.hh:136
gazebo::common::Logger::STDERR
Output to stderr.
Definition: Console.hh:145
gazebo::common::Logger::Buffer::sync
virtual int sync()
Sync the stream (output the string buffer contents).
gazebo::common::Console::log
static FileLogger log
Global instance of the file logger.
Definition: Console.hh:228
gazebo::common::Logger::operator()
virtual Logger & operator()()
Access operator.
gazebo::common::Logger::Buffer
String buffer for the base logger.
Definition: Console.hh:170
gazebo::common::FileLogger::Buffer::stream
std::ofstream * stream
Stream to output information into.
Definition: Console.hh:126
gazebo::common::Console
Container for loggers, and global logging options (such as verbose vs. quiet output).
Definition: Console.hh:205
gazebo::common::FileLogger
A logger that outputs messages to a file.
Definition: Console.hh:70
gazebo::common::FileLogger::operator()
virtual FileLogger & operator()()
Output a filename and line number, then return a reference to the logger.
gazebo::common::FileLogger::Buffer::~Buffer
virtual ~Buffer()
Destructor.
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
gazebo::common::Console::GetQuiet
static bool GetQuiet()
Get whether quiet output is set.
gazebo::common::FileLogger::~FileLogger
virtual ~FileLogger()
Destructor.
gazebo::common::FileLogger::FileLogger
FileLogger(const std::string &_filename="")
Constructor.
gazebo::common::Console::err
static Logger err
Global instance of the error logger.
Definition: Console.hh:219
SingletonT.hh
gazebo::common::Console::warn
static Logger warn
Global instance of the warning logger.
Definition: Console.hh:225