Claw  1.7.0
application.cpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
30 #include <claw/application.hpp>
31 
32 #include <claw/logger.hpp>
33 #include <claw/log_stream_uniq.hpp>
35 #include <claw/claw_gettext.hpp>
36 
37 #define CLAW_MK_STR_(e) #e
38 #define CLAW_MK_STR(e) CLAW_MK_STR_(e)
39 
40 /*----------------------------------------------------------------------------*/
49 claw::application::application( int& argc, char** &argv )
50  : m_arguments( argc, argv )
51 {
52  setlocale( LC_ALL, "" );
53 #ifdef CLAW_TEXT_DOMAIN_PATH
54  bindtextdomain( "libclaw", CLAW_MK_STR(CLAW_TEXT_DOMAIN_PATH) );
55 #endif
56  bind_textdomain_codeset( "libclaw", "UTF-8" );
57  textdomain("libclaw");
58 
60  ("--log-file", claw_gettext("The file to use to store log informations."),
61  true, claw_gettext("file") );
63  ("--log-level",
64  claw_gettext("Level of log informations:\n"
65  "\t\terror: error messages,\n"
66  "\t\twarning: warning and error messages,\n"
67  "\t\tverbose: all messages."), true, claw_gettext("string") );
69  ("--log-uniq",
70  claw_gettext
71  ("Use a logger that does not output successively the same message."),
72  true );
74  ("--log-concise",
75  claw_gettext
76  ("Use a logger that does not output messages that have been recently"
77  " output."), true, claw_gettext("integer") );
78 
79  m_arguments.parse( argc, argv );
80 
81  log_stream* log;
82 
83  if ( m_arguments.has_value("--log-file") )
84  log = new file_logger( m_arguments.get_string("--log-file") );
85  else
86  log = new console_logger;
87 
88  if ( m_arguments.get_bool("--log-uniq") )
89  log = new log_stream_uniq(log);
90  else if ( m_arguments.has_value("--log-concise")
91  && m_arguments.only_integer_values("--log-concise")
92  && m_arguments.get_integer("--log-concise") > 0 )
93  log = new log_stream_concise(log, m_arguments.get_integer("--log-concise"));
94  else if ( m_arguments.get_bool("--log-concise") )
95  log = new log_stream_concise(log);
96 
97  logger.set( log );
98 
99  if ( m_arguments.has_value( "--log-level" ) )
100  {
101  std::string level = m_arguments.get_string("--log-level");
102 
103  if ( (level == "error") || (level == claw_gettext("error")) )
104  logger.set_level( log_error );
105  else if ( (level == "warning") || (level == claw_gettext("warning")) )
106  logger.set_level( log_warning );
107  else if ( (level == "verbose") || (level == claw_gettext("verbose")) )
108  logger.set_level( log_verbose );
109  else
110  logger.set_level( m_arguments.get_integer("--log-level") );
111  }
112 
113 } // application::application()
114 
115 /*----------------------------------------------------------------------------*/
120 {
121  logger.clear();
122 } // application::~application()