All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Console.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 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  * Desc: Gazebo Message
19  * Author: Nathan Koenig
20  * Date: 09 June 2007
21  */
22 
23 #ifndef _GAZEBO_CONSOLE_HH_
24 #define _GAZEBO_CONSOLE_HH_
25 
26 #include <iostream>
27 #include <fstream>
28 #include <string>
29 
32 
33 namespace gazebo
34 {
35  namespace common
36  {
39 
41  #define gzmsg (gazebo::common::Console::Instance()->ColorMsg("Msg", 32))
42 
44  #define gzdbg (gazebo::common::Console::Instance()->ColorMsg("Dbg", 36))
45 
47  #define gzwarn (gazebo::common::Console::Instance()->ColorErr("Warning", \
48  __FILE__, __LINE__, 33))
49 
51  #define gzerr (gazebo::common::Console::Instance()->ColorErr("Error", \
52  __FILE__, __LINE__, 31))
53 
55  #define gzlog (gazebo::common::Console::Instance()->Log())
56 
58  #define gzclr_start(clr) "\033[1;33m"
59 
61  #define gzclr_end "\033[0m"
62 
65 
68 
69  class Console : public SingletonT<Console>
70  {
72  private: Console();
73 
75  private: virtual ~Console();
76 
78  public: void Init(const std::string &_logFilename);
79 
82  public: void SetQuiet(bool _q);
83 
88  public: std::ostream &ColorMsg(const std::string &_lbl, int _color);
89 
93  public: std::ofstream &Log();
94 
101  public: std::ostream &ColorErr(const std::string &_lbl,
102  const std::string &_file, unsigned int _line, int _color);
103 
104 
107  private: class NullStream : public std::ostream
108  {
110  public: NullStream() : std::ios(0), std::ostream(0) {}
111  };
112 
114  private: NullStream nullStream;
115 
117  private: std::ostream *msgStream;
118 
120  private: std::ostream *errStream;
121 
123  private: std::ofstream *logStream;
124 
126  private: friend class SingletonT<Console>;
127  };
129  }
130 }
131 #endif