logger_util.cc

Go to the documentation of this file.
00001 /*
00002    The lestes compiler suite
00003    Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy
00004    Copyright (C) 2002, 2003, 2004, 2005 Petr Zika
00005    Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala
00006    Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina
00007    Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda
00008    Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar
00009    Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; version 2 of the License.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    See the full text of the GNU General Public License version 2, and
00021    the limitations in the file doc/LICENSE.
00022 
00023    By accepting the license the licensee waives any and all claims
00024    against the copyright holder(s) related in whole or in part to the
00025    work, its use, and/or the inability to use it.
00026  
00027  */
00028 #include <lestes/common.hh>
00029 #include <lestes/msg/logger.hh>
00030 #include <lestes/msg/logger_util.hh>
00031 
00032 /*! \file
00033   \author TMA
00034  */
00035 
00036 #include <iostream>
00037 
00038 package(lestes);
00039 package(msg);
00040 
00041 logger_end_marker eolog;
00042 
00043 ::std::ostream & operator << (::std::ostream & os,const logger_end_marker &)
00044 {
00045         return os;
00046 }
00047 
00048 binded_logger::binded_logger(ptr < logger > l)
00049         : log(l), stream(&(*l << l->formatter_get()))
00050 { }
00051 
00052 binded_logger::binded_logger(const binded_logger & l)
00053         : log(l.log), stream(l.stream)
00054 { }
00055 
00056 binded_logger::~binded_logger()
00057 {
00058         //*this << eolog;
00059 }
00060 
00061 void binded_logger::operator << (const logger_end_marker &) const
00062 {
00063         log->formatter_get()->format_end(log, *stream);
00064 }
00065 
00066 ptr < logger_formatter > formatter_factory::create_formatter(lstring name, lstring parameter)
00067 {
00068         if (name == "color" || name == "colorific")
00069                 return color_formatter::create(parameter);
00070         else if (name == "simple" || name == "plain" || name == "")
00071                 return plain_formatter::instance();
00072         else if (name == "shortname")
00073                 return ::lestes::msg::shortname_formatter::instance();
00074         else if (name == "fullname")
00075                 return ::lestes::msg::fullname_formatter::instance();
00076         else if (name[0] == '(') {
00077                 bool is_parameter_list = parameter[0] == '(';
00078                 lstring::size_type sz = 1, psz = is_parameter_list;
00079                 lstring::size_type nsz, npsz = parameter.size();
00080                 ptr < logger_formatter > lf = NULL;
00081                 for ( ; (nsz = name.find_first_of(" )", sz)) != lstring::npos ; sz = nsz+1) {
00082                         lstring formater = name.substr(sz,nsz - sz);
00083                         lstring param;
00084                         ptr < logger_formatter > nlf;
00085                         if (is_parameter_list) {
00086                                 npsz = parameter.find_first_of(" )",psz);
00087                                 if (npsz != lstring::npos) {
00088                                         param = parameter.substr(psz,npsz-psz);
00089                                         psz = npsz + 1;
00090                                 } else
00091                                         param = "";
00092                         } else
00093                                 param = parameter;
00094 
00095                         nlf = create_formatter(formater, param);
00096 
00097                         if (lf)
00098                                 lf = conjunct_formatter::create(lf, nlf);
00099                         else
00100                                 lf = nlf;
00101                 }
00102                 return lf;
00103         }
00104         /*else if (name == "xml")
00105                 return xml_formatter(parameter); */
00106         ::std::cerr << "unknown formatter (" << name << ")" << ::std::endl;
00107         return plain_formatter::instance();
00108 }
00109 
00110 
00111 end_package(msg);
00112 end_package(lestes);

Generated on Mon Feb 12 18:22:38 2007 for lestes by doxygen 1.5.1-20070107