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 2011 Nate Koenig
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 
30 #include "common/CommonTypes.hh"
31 
32 namespace gazebo
33 {
34  namespace common
35  {
38 
40  #define gzmsg (gazebo::common::Console::Instance()->ColorMsg("Msg", 32))
41 
43  #define gzdbg (gazebo::common::Console::Instance()->ColorMsg("Dbg", 36))
44 
46  #define gzwarn (gazebo::common::Console::Instance()->ColorErr("Warning", \
47  __FILE__, __LINE__, 33))
48 
50  #define gzerr (gazebo::common::Console::Instance()->ColorErr("Error", \
51  __FILE__, __LINE__, 31))
52 
54  #define gzlog (gazebo::common::Console::Instance()->Log() << "[" <<\
55  __FILE__ << ":" << __LINE__ << "] ")
56 
58  #define gzclr_start(clr) "\033[1;33m"
59 
60  #define gzclr_end "\033[0m"
61 
63  class Console
64  {
66  private: Console();
67 
69  private: virtual ~Console();
70 
72  public: static Console *Instance();
73 
75  public: void Load();
76 
79  public: void SetQuiet(bool _q);
80 
85  public: std::ostream &ColorMsg(const std::string &_lbl, int _color);
86 
93  public: std::ostream &ColorErr(const std::string &_lbl,
94  const std::string &_file, unsigned int _line, int _color);
95 
98  public: std::ofstream &Log();
99 
101  private: bool logData;
102 
104  private: class NullStream : public std::ostream
105  {
107  public: NullStream() : std::ios(0), std::ostream(0) {}
108  };
109 
111  private: NullStream nullStream;
112 
114  private: std::ostream *msgStream;
115 
117  private: std::ostream *errStream;
118 
120  private: std::ofstream logStream;
121 
123  private: static Console *myself;
124  };
126  }
127 }
128 #endif