Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 }
00108
00109
00113 claw::application::~application()
00114 {
00115 logger.clear();
00116 }