00001 /* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org> 00002 * 00003 * schroot is free software; you can redistribute it and/or modify it 00004 * under the terms of the GNU General Public License as published by 00005 * the Free Software Foundation; either version 2 of the License, or 00006 * (at your option) any later version. 00007 * 00008 * schroot is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * along with this program; if not, write to the Free Software 00015 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00016 * MA 02111-1307 USA 00017 * 00018 *********************************************************************/ 00019 00020 #include <config.h> 00021 00022 #include "sbuild-error.h" 00023 #include "sbuild-i18n.h" 00024 #include "sbuild-log.h" 00025 #include "sbuild-nostream.h" 00026 #include "sbuild-util.h" 00027 00028 #include <iostream> 00029 00030 #include <boost/format.hpp> 00031 00032 using boost::format; 00033 00034 std::ostream& 00035 sbuild::log_info () 00036 { 00037 // TRANSLATORS: "I" is an abbreviation of "Information" 00038 return std::cerr << _("I: "); 00039 } 00040 00041 std::ostream& 00042 sbuild::log_warning () 00043 { 00044 // TRANSLATORS: "W" is an abbreviation of "Warning" 00045 return std::cerr << _("W: "); 00046 } 00047 00048 std::ostream& 00049 sbuild::log_error () 00050 { 00051 // TRANSLATORS: "E" is an abbreviation of "Error" 00052 return std::cerr << _("E: "); 00053 } 00054 00055 std::ostream& 00056 sbuild::log_debug (sbuild::DebugLevel level) 00057 { 00058 if (debug_level > 0 && 00059 level >= debug_level) 00060 // TRANSLATORS: %1% = integer debug level 00061 // TRANSLATORS: "D" is an abbreviation of "Debug" 00062 return std::cerr << format(_("D(%1%): ")) % level; 00063 else 00064 return sbuild::cnull; 00065 } 00066 00067 void 00068 sbuild::log_exception_warning (std::exception const& e) 00069 { 00070 log_warning() << e.what() << std::endl; 00071 00072 try 00073 { 00074 sbuild::error_base const& eb(dynamic_cast<sbuild::error_base const&>(e)); 00075 string_list lines = split_string(eb.why(), "\n"); 00076 for (string_list::const_iterator line = lines.begin(); 00077 line != lines.end(); 00078 ++line) 00079 log_info() << *line << std::endl; 00080 } 00081 catch (std::bad_cast const& discard) 00082 { 00083 } 00084 } 00085 00086 void 00087 sbuild::log_exception_error (std::exception const& e) 00088 { 00089 log_error() << e.what() << std::endl; 00090 00091 try 00092 { 00093 sbuild::error_base const& eb(dynamic_cast<sbuild::error_base const&>(e)); 00094 string_list lines = split_string(eb.why(), "\n"); 00095 for (string_list::const_iterator line = lines.begin(); 00096 line != lines.end(); 00097 ++line) 00098 log_info() << *line << std::endl; 00099 } 00100 catch (std::bad_cast const& discard) 00101 { 00102 } 00103 } 00104 00105 sbuild::DebugLevel sbuild::debug_level = sbuild::DEBUG_NONE;