Console.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 /*
00018  * Desc: Gazebo Message
00019  * Author: Nathan Koenig
00020  * Date: 09 June 2007
00021  */
00022 
00023 #ifndef GAZEBO_CONSOLE_HH
00024 #define GAZEBO_CONSOLE_HH
00025 
00026 #include <iostream>
00027 #include <fstream>
00028 #include <string>
00029 
00030 #include "common/CommonTypes.hh"
00031 
00032 namespace gazebo
00033 {
00034     namespace common
00035   {
00038 
00040     #define gzmsg (gazebo::common::Console::Instance()->ColorMsg("Msg", 32))
00041 
00043     #define gzdbg (gazebo::common::Console::Instance()->ColorMsg("Dbg", 36))
00044 
00046     #define gzwarn (gazebo::common::Console::Instance()->ColorErr("Warning",__FILE__, __LINE__,33))
00047   
00049     #define gzerr (gazebo::common::Console::Instance()->ColorErr("Error",__FILE__, __LINE__,31))
00050    
00052     #define gzlog (gazebo::common::Console::Instance()->Log() << "[" << __FILE__ << ":" << __LINE__ << "] ")
00053 
00055     class Console
00056     {
00058       private: Console();
00059     
00061       private: virtual ~Console();
00062     
00064       public: static Console *Instance();
00065     
00067       public: void Load();
00068     
00071       public: void SetQuiet( bool q );
00072     
00075       public: std::ostream &ColorMsg(const std::string &lbl, int color);
00076   
00079       public: std::ostream &ColorErr(const std::string &lbl, const std::string &file, unsigned int line, int color);
00080     
00082       public: std::ofstream &Log();
00083     
00085       private: bool logData;
00086    
00087       private: class NullStream : public std::ostream
00088                {
00089                  public: NullStream() : std::ios(0), std::ostream(0) {}
00090                };
00091   
00092       private: NullStream nullStream;
00093       private: std::ostream *msgStream;
00094       private: std::ostream *errStream;
00095       private: std::ofstream logStream;
00096   
00098       private: static Console *myself;
00099     };
00100 
00102   }
00103 }
00104 #endif