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: bool IsInitialized() const;
83 
86  public: void SetQuiet(bool _q);
87 
90  public: bool GetQuiet() const;
91 
96  public: std::ostream &ColorMsg(const std::string &_lbl, int _color);
97 
101  public: std::ofstream &Log();
102 
109  public: std::ostream &ColorErr(const std::string &_lbl,
110  const std::string &_file, unsigned int _line, int _color);
111 
112 
115  private: class NullStream : public std::ostream
116  {
118  public: NullStream() : std::ios(0), std::ostream(0) {}
119  };
120 
122  private: NullStream nullStream;
123 
125  private: std::ostream *msgStream;
126 
128  private: std::ostream *errStream;
129 
131  private: std::ofstream *logStream;
132 
134  private: bool quiet;
135 
137  private: friend class SingletonT<Console>;
138  };
140  }
141 }
142 #endif