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