EvolvingObjects
|
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- 00002 00003 /* 00004 (c) Thales group, 2010 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; 00009 version 2 of the License. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 Contact: http://eodev.sourceforge.net 00021 00022 Authors: 00023 Johann Dréo <johann.dreo@thalesgroup.com> 00024 Caner Candan <caner.candan@thalesgroup.com> 00025 00026 */ 00027 00087 #ifndef eoLogger_h 00088 #define eoLogger_h 00089 00090 #include <map> 00091 #include <vector> 00092 #include <string> 00093 #include <iosfwd> 00094 00095 #include "eoObject.h" 00096 #include "eoParser.h" 00097 00098 namespace eo 00099 { 00105 enum Levels {quiet = 0, 00106 errors, 00107 warnings, 00108 progress, 00109 logging, 00110 debug, 00111 xdebug}; 00112 00117 struct file 00118 { 00119 file(const std::string f); 00120 const std::string _f; 00121 }; 00122 00127 struct setlevel 00128 { 00129 setlevel(const std::string v); 00130 setlevel(const Levels lvl); 00131 const std::string _v; 00132 const Levels _lvl; 00133 }; 00134 } 00135 00141 class eoLogger : public eoObject, 00142 public std::ostream 00143 { 00144 public: 00146 eoLogger(); 00147 00149 eoLogger(eo::file file); 00150 00152 ~eoLogger(); 00153 00155 virtual std::string className() const; 00156 00159 void printLevels() const; 00160 00166 inline eo::Levels getLevelSelected() const { return _selectedLevel; } 00167 00171 inline eo::Levels getLevelContext() const { return _contextLevel; } 00172 00173 protected: 00175 void addLevel(std::string name, eo::Levels level); 00176 00177 private: 00179 void _createParameters( eoParser& ); 00180 00182 void _init(); 00183 00184 private: 00189 class outbuf : public std::streambuf 00190 { 00191 public: 00192 outbuf(const int& fd, const eo::Levels& contexlvl, const eo::Levels& selectedlvl); 00193 protected: 00194 virtual int overflow(int_type c); 00195 private: 00196 const int& _fd; 00197 const eo::Levels& _contextLevel; 00198 const eo::Levels& _selectedLevel; 00199 }; 00200 00201 private: 00205 typedef std::map<std::string, eo::Levels> MapLevel; 00206 00207 public: 00211 00212 friend eoLogger& operator<<(eoLogger&, const eo::Levels); 00213 00217 00218 friend eoLogger& operator<<(eoLogger&, eo::file); 00219 00223 00224 friend eoLogger& operator<<(eoLogger&, eo::setlevel); 00225 00229 00230 00231 friend eoLogger& operator<<(eoLogger&, std::ostream&); 00232 00233 private: 00234 friend void make_verbose(eoParser&); 00235 00236 eoValueParam<std::string> _verbose; 00237 eoValueParam<bool> _printVerboseLevels; 00238 eoValueParam<std::string> _output; 00239 00243 eo::Levels _selectedLevel; 00244 eo::Levels _contextLevel; 00245 00250 int _fd; 00251 00255 outbuf _obuf; 00256 00260 MapLevel _levels; 00261 00265 std::vector<std::string> _sortedLevels; 00266 00270 std::map< std::ostream*, int > _standard_io_streams; 00271 }; 00275 00276 void make_verbose(eoParser&); 00277 00278 namespace eo 00279 { 00283 extern eoLogger log; 00284 } 00285 00288 #endif // !eoLogger_h