CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
|
00001 /* 00002 CLAW - a C++ Library Absolutely Wonderful 00003 00004 CLAW is a free library without any particular aim but being useful to 00005 anyone. 00006 00007 Copyright (C) 2005-2010 Julien Jorge 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 contact: julien_jorge@yahoo.fr 00024 */ 00030 #include <claw/application.hpp> 00031 00032 #include <claw/logger.hpp> 00033 #include <claw/log_stream_uniq.hpp> 00034 #include <claw/log_stream_concise.hpp> 00035 #include <claw/claw_gettext.hpp> 00036 00037 /*----------------------------------------------------------------------------*/ 00046 claw::application::application( int& argc, char** &argv ) 00047 : m_arguments( argc, argv ) 00048 { 00049 setlocale( LC_ALL, "" ); 00050 bind_textdomain_codeset( "libclaw", "UTF-8" ); 00051 textdomain("libclaw"); 00052 00053 m_arguments.add_long 00054 ("--log-file", claw_gettext("The file to use to store log informations."), 00055 true, claw_gettext("file") ); 00056 m_arguments.add_long 00057 ("--log-level", 00058 claw_gettext("Level of log informations:\n" 00059 "\t\terror: error messages,\n" 00060 "\t\twarning: warning and error messages,\n" 00061 "\t\tverbose: all messages."), true, claw_gettext("string") ); 00062 m_arguments.add_long 00063 ("--log-uniq", 00064 claw_gettext 00065 ("Use a logger that does not output successively the same message."), 00066 true ); 00067 m_arguments.add_long 00068 ("--log-concise", 00069 claw_gettext 00070 ("Use a logger that does not output messages that have been recently" 00071 " output."), true, claw_gettext("integer") ); 00072 00073 m_arguments.parse( argc, argv ); 00074 00075 log_stream* log; 00076 00077 if ( m_arguments.has_value("--log-file") ) 00078 log = new file_logger( m_arguments.get_string("--log-file") ); 00079 else 00080 log = new console_logger; 00081 00082 if ( m_arguments.get_bool("--log-uniq") ) 00083 log = new log_stream_uniq(log); 00084 else if ( m_arguments.has_value("--log-concise") 00085 && m_arguments.only_integer_values("--log-concise") 00086 && m_arguments.get_integer("--log-concise") > 0 ) 00087 log = new log_stream_concise(log, m_arguments.get_integer("--log-concise")); 00088 else if ( m_arguments.get_bool("--log-concise") ) 00089 log = new log_stream_concise(log); 00090 00091 logger.set( log ); 00092 00093 if ( m_arguments.has_value( "--log-level" ) ) 00094 { 00095 std::string level = m_arguments.get_string("--log-level"); 00096 00097 if ( (level == "error") || (level == claw_gettext("error")) ) 00098 logger.set_level( log_error ); 00099 else if ( (level == "warning") || (level == claw_gettext("warning")) ) 00100 logger.set_level( log_warning ); 00101 else if ( (level == "verbose") || (level == claw_gettext("verbose")) ) 00102 logger.set_level( log_verbose ); 00103 else 00104 logger.set_level( m_arguments.get_integer("--log-level") ); 00105 } 00106 00107 } // application::application() 00108 00109 /*----------------------------------------------------------------------------*/ 00113 claw::application::~application() 00114 { 00115 logger.clear(); 00116 } // application::~application()