logger_formatters.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/msg/logger.hh>
00029 #include <lestes/msg/logger_util.hh>
00030 #include <lestes/std/objectize_macros.hh>
00031 #include <stack>
00032 #include <iostream>
00033 #include <fstream>
00034 
00035 #include <libxml/xmlmemory.h>
00036 #include <libxml/parser.h>
00037 
00038 package(lestes);
00039 package(msg);
00040 
00041 lstring logger2fullname( const ptr<logger> &l )
00042 {
00043         lstring full_name;
00044         for ( ptr<logger> i = l; i != logger::root_instance(); i = i->parent_get() )
00045                 full_name = "/" + i->name_get() + full_name;
00046         if (full_name.empty())
00047                 full_name = "/";
00048         return full_name;
00049 }
00050 
00051 lstring logger2shortname( const ptr<logger> &l )
00052 {
00053         lstring full_name;
00054         full_name = l->name_get();
00055         if (full_name.empty())
00056                 full_name = "/";
00057         return full_name;
00058 }
00059 
00060 fullname_formatter::fullname_formatter() : logger_formatter()
00061 {}
00062 
00063 ptr<fullname_formatter> fullname_formatter::the_instance = the_instance;
00064 
00065 ptr<fullname_formatter> fullname_formatter::instance()
00066 {
00067         if (!the_instance)
00068                 the_instance = new fullname_formatter();
00069         return the_instance;
00070 }
00071 
00072 ::std::ostream & fullname_formatter::format( const ptr<logger> &l, ::std::ostream & os )
00073 {
00074         return os << logger2fullname(l) << ": ";
00075 }
00076 
00077 void fullname_formatter::format_end( const ptr<logger> &, ::std::ostream & )
00078 {
00079 }
00080 
00081 plain_formatter::plain_formatter() : logger_formatter()
00082 {}
00083 
00084 ptr<plain_formatter> plain_formatter::the_instance = the_instance;
00085 
00086 ptr<plain_formatter> plain_formatter::instance()
00087 {
00088         if (!the_instance)
00089                 the_instance = new plain_formatter();
00090         return the_instance;
00091 }
00092 
00093 ::std::ostream & plain_formatter::format( const ptr<logger> &, ::std::ostream & os )
00094 {
00095         return os;
00096 }
00097 
00098 void plain_formatter::format_end( const ptr<logger> &, ::std::ostream & )
00099 {
00100 }
00101 
00102 xml_formatter::xml_formatter() : logger_formatter(), tag_name("not-set-yet")
00103 {}
00104 
00105 ptr<xml_formatter> xml_formatter::the_instance = the_instance;
00106 
00107 ptr<xml_formatter> xml_formatter::instance()
00108 {
00109         if (!the_instance)
00110                 the_instance = new xml_formatter();
00111         return the_instance;
00112 }
00113 
00114 ::std::ostream & xml_formatter::format( const ptr<logger> &l, ::std::ostream & os )
00115 {
00116         return os << '<' << tag_name << " by=\"" << logger2fullname(l) << "\">";
00117 }
00118 
00119 void xml_formatter::format_end( const ptr<logger> &, ::std::ostream & )
00120 {
00121 }
00122 
00123 void xml_formatter::tag_name_set( const lstring & a_tag_name )
00124 {
00125         tag_name = a_tag_name;
00126 }
00127 
00128 lstring xml_formatter::tag_name_get() const
00129 {
00130         return tag_name;
00131 }
00132 
00133 conjunct_formatter::conjunct_formatter(const ptr < logger_formatter > & f, const ptr < logger_formatter > & s)
00134         : first(checked(f)), second(checked(s))
00135 { }
00136 
00137 ptr < conjunct_formatter > conjunct_formatter::create(const ptr < logger_formatter > & f, const ptr < logger_formatter > & s)
00138 {
00139         return new conjunct_formatter(f, s);
00140 }
00141 
00142 void conjunct_formatter::gc_mark()
00143 {
00144         first.gc_mark();
00145         second.gc_mark();
00146         logger_formatter::gc_mark();
00147 }
00148 
00149 ::std::ostream & conjunct_formatter::format(const ptr<logger> & l, ::std::ostream & os)
00150 {
00151         return second->format(l,first->format(l, os));
00152 }
00153 void conjunct_formatter::format_end(const ptr<logger> & l, ::std::ostream & os)
00154 {
00155         second->format_end(l,os);
00156         first->format_end(l,os);
00157 }
00158 
00159 
00160 color_formatter::color_formatter(lstring b)
00161         : begin(b)
00162 { }
00163 
00164 ::std::ostream & color_formatter::format(const ptr<logger> &, ::std::ostream & os)
00165 {
00166         return os << begin;
00167 }
00168 void color_formatter::format_end(const ptr<logger> &, ::std::ostream & os)
00169 {
00170         os << "\033[m";
00171 }
00172 
00173 ptr < color_formatter > color_formatter::create(lstring color)
00174 {
00175         lstring b;
00176         if (color == "black" || color == "0")
00177                 b = "\033[0;30m";
00178         else if (color == "red" || color == "1")
00179                 b = "\033[0;31m";
00180         else if (color == "green" || color == "2")
00181                 b = "\033[0;32m";
00182         else if (color == "yellow" || color == "3")
00183                 b = "\033[0;33m";
00184         else if (color == "blue" || color == "4")
00185                 b = "\033[0;34m";
00186         else if (color == "magenta" || color == "5")
00187                 b = "\033[0;35m";
00188         else if (color == "cyan" || color == "6")
00189                 b = "\033[0;36m";
00190         else if (color == "white" || color == "7")
00191                 b = "\033[0;37m";
00192         else if (color == "bright-black" || color == "bright black" || color == "8")
00193                 b = "\033[1;30m";
00194         else if (color == "bright-red" || color == "bright red" || color == "9")
00195                 b = "\033[1;31m";
00196         else if (color == "bright-green" || color == "bright green" || color == "10")
00197                 b = "\033[1;32m";
00198         else if (color == "bright-yellow" || color == "bright yellow" || color == "11")
00199                 b = "\033[1;33m";
00200         else if (color == "bright-blue" || color == "bright blue" || color == "12")
00201                 b = "\033[1;34m";
00202         else if (color == "bright-magenta" || color == "bright magenta" || color == "13")
00203                 b = "\033[1;35m";
00204         else if (color == "bright-cyan" || color == "bright cyan" || color == "14")
00205                 b = "\033[1;36m";
00206         else if (color == "bright-white" || color == "bright white" || color == "15")
00207                 b = "\033[1;37m";
00208         else
00209                 b = "";
00210 
00211         return new color_formatter(b);
00212 }
00213 
00214 ptr < shortname_formatter > shortname_formatter::the_instance = the_instance;
00215 
00216 shortname_formatter::shortname_formatter()
00217 { }
00218 
00219 ::std::ostream & shortname_formatter::format(const ptr<logger> & log, ::std::ostream & os)
00220 {
00221         return os << logger2shortname(log) << ": ";
00222 }
00223 void shortname_formatter::format_end(const ptr<logger> &, ::std::ostream &)
00224 {
00225 }
00226 
00227 ptr < shortname_formatter > shortname_formatter::instance()
00228 {
00229         if (!the_instance)
00230                 the_instance = new shortname_formatter();
00231         return the_instance;
00232 }
00233 
00234 end_package(msg);
00235 end_package(lestes);
00236 

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