Claw
1.7.0
|
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-2011 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@gamned.org 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 #define CLAW_MK_STR_(e) #e 00038 #define CLAW_MK_STR(e) CLAW_MK_STR_(e) 00039 00040 /*----------------------------------------------------------------------------*/ 00049 claw::application::application( int& argc, char** &argv ) 00050 : m_arguments( argc, argv ) 00051 { 00052 setlocale( LC_ALL, "" ); 00053 #ifdef CLAW_TEXT_DOMAIN_PATH 00054 bindtextdomain( "libclaw", CLAW_MK_STR(CLAW_TEXT_DOMAIN_PATH) ); 00055 #endif 00056 bind_textdomain_codeset( "libclaw", "UTF-8" ); 00057 textdomain("libclaw"); 00058 00059 m_arguments.add_long 00060 ("--log-file", claw_gettext("The file to use to store log informations."), 00061 true, claw_gettext("file") ); 00062 m_arguments.add_long 00063 ("--log-level", 00064 claw_gettext("Level of log informations:\n" 00065 "\t\terror: error messages,\n" 00066 "\t\twarning: warning and error messages,\n" 00067 "\t\tverbose: all messages."), true, claw_gettext("string") ); 00068 m_arguments.add_long 00069 ("--log-uniq", 00070 claw_gettext 00071 ("Use a logger that does not output successively the same message."), 00072 true ); 00073 m_arguments.add_long 00074 ("--log-concise", 00075 claw_gettext 00076 ("Use a logger that does not output messages that have been recently" 00077 " output."), true, claw_gettext("integer") ); 00078 00079 m_arguments.parse( argc, argv ); 00080 00081 log_stream* log; 00082 00083 if ( m_arguments.has_value("--log-file") ) 00084 log = new file_logger( m_arguments.get_string("--log-file") ); 00085 else 00086 log = new console_logger; 00087 00088 if ( m_arguments.get_bool("--log-uniq") ) 00089 log = new log_stream_uniq(log); 00090 else if ( m_arguments.has_value("--log-concise") 00091 && m_arguments.only_integer_values("--log-concise") 00092 && m_arguments.get_integer("--log-concise") > 0 ) 00093 log = new log_stream_concise(log, m_arguments.get_integer("--log-concise")); 00094 else if ( m_arguments.get_bool("--log-concise") ) 00095 log = new log_stream_concise(log); 00096 00097 logger.set( log ); 00098 00099 if ( m_arguments.has_value( "--log-level" ) ) 00100 { 00101 std::string level = m_arguments.get_string("--log-level"); 00102 00103 if ( (level == "error") || (level == claw_gettext("error")) ) 00104 logger.set_level( log_error ); 00105 else if ( (level == "warning") || (level == claw_gettext("warning")) ) 00106 logger.set_level( log_warning ); 00107 else if ( (level == "verbose") || (level == claw_gettext("verbose")) ) 00108 logger.set_level( log_verbose ); 00109 else 00110 logger.set_level( m_arguments.get_integer("--log-level") ); 00111 } 00112 00113 } // application::application() 00114 00115 /*----------------------------------------------------------------------------*/ 00119 claw::application::~application() 00120 { 00121 logger.clear(); 00122 } // application::~application()