All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Console.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 Open Source Robotics Foundation
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 */
17 
18 #ifndef _GAZEBO_CONSOLE_HH_
19 #define _GAZEBO_CONSOLE_HH_
20 
21 #include <iostream>
22 #include <fstream>
23 #include <sstream>
24 #include <string>
25 
26 #include <boost/thread.hpp>
29 #include "gazebo/util/system.hh"
30 
31 namespace gazebo
32 {
33  namespace common
34  {
38  #define gzmsg (gazebo::common::Console::msg())
39 
41  #define gzdbg (gazebo::common::Console::dbg(__FILE__, __LINE__))
42 
44  #define gzwarn (gazebo::common::Console::warn(__FILE__, __LINE__))
45 
47  #define gzerr (gazebo::common::Console::err(__FILE__, __LINE__))
48 
50  #define gzlog (gazebo::common::Console::log())
51 
56  #define gzLogInit(_str) (gazebo::common::Console::log.Init(_str))
57 
60  class GAZEBO_VISIBLE FileLogger : public std::ostream
61  {
65  public: FileLogger(const std::string &_filename = "");
66 
68  public: virtual ~FileLogger();
69 
73  public: void Init(const std::string &_filename);
74 
78  public: virtual FileLogger &operator()();
79 
85  public: virtual FileLogger &operator()(
86  const std::string &_file, int _line);
87 
89  protected: class Buffer : public std::stringbuf
90  {
93  public: Buffer(const std::string &_filename);
94 
96  public: virtual ~Buffer();
97 
101  public: virtual int sync();
102 
104  public: std::ofstream *stream;
105  };
106  };
107 
110  class GAZEBO_VISIBLE Logger : public std::ostream
111  {
114  public: enum LogType
115  {
119  STDERR
120  };
121 
126  public: Logger(const std::string &_prefix, int _color, LogType _type);
127 
129  public: virtual ~Logger();
130 
133  public: virtual Logger &operator()();
134 
140  public: virtual Logger &operator()(
141  const std::string &_file, int _line);
142 
144  protected: class Buffer : public std::stringbuf
145  {
150  public: Buffer(LogType _type, int _color);
151 
153  public: virtual ~Buffer();
154 
158  public: virtual int sync();
159 
161  public: LogType type;
162 
166  public: int color;
167  };
168 
170  public: int color;
171 
173  private: std::string prefix;
174  };
175 
180  {
183  public: static void SetQuiet(bool _q);
184 
187  public: static bool GetQuiet();
188 
190  public: static Logger msg;
191 
193  public: static Logger err;
194 
196  public: static Logger dbg;
197 
199  public: static Logger warn;
200 
202  public: static FileLogger log;
203 
205  private: static bool quiet;
206  };
208  }
209 }
210 #endif
Terminal logger.
Definition: Console.hh:110
LogType type
Destination type for the messages.
Definition: Console.hh:161
static Logger msg
Global instance of the message logger.
Definition: Console.hh:190
Output to stdout.
Definition: Console.hh:117
int color
ANSI color code using Select Graphic Rendition parameters (SGR).
Definition: Console.hh:166
static Logger dbg
Global instance of the debug logger.
Definition: Console.hh:196
String buffer for the base logger.
Definition: Console.hh:144
Container for loggers, and global logging options (such as verbose vs.
Definition: Console.hh:179
std::ofstream * stream
Stream to output information into.
Definition: Console.hh:104
static FileLogger log
Global instance of the file logger.
Definition: Console.hh:202
A logger that outputs messages to a file.
Definition: Console.hh:60
static Logger err
Global instance of the error logger.
Definition: Console.hh:193
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
LogType
Definition: Console.hh:114
String buffer for the file logger.
Definition: Console.hh:89
static Logger warn
Global instance of the warning logger.
Definition: Console.hh:199
int color
Color for the output.
Definition: Console.hh:170
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48