application.cpp

Go to the documentation of this file.
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-2008 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 #include <claw/logger.hpp>
00032 
00033 /*----------------------------------------------------------------------------*/
00042 claw::application::application( int& argc, char** &argv )
00043   : m_arguments( argc, argv )
00044 {
00045   m_arguments.add_long("--log-file",
00046                        "The file to use to store log informations.", true,
00047                        "file" );
00048   m_arguments.add_long("--log-level",
00049                        "Level of log informations:\n"
00050            "\t\terror: error messages,\n"
00051                        "\t\twarning: warning and error messages,\n"
00052                        "\t\tverbose: all messages.", true, "string" );
00053   m_arguments.parse( argc, argv );
00054 
00055   if ( m_arguments.has_value("--log-file") )
00056     {
00057       std::string log_file = m_arguments.get_string("--log-file");
00058       logger.set( new file_logger(log_file) );
00059     }
00060   else
00061     logger.set( new console_logger() );
00062 
00063   if ( m_arguments.has_value( "--log-level" ) )
00064     {
00065       std::string level = m_arguments.get_string("--log-level");
00066 
00067       if (level == "error")
00068   logger.set_level( log_error );
00069       else if (level == "warning")
00070   logger.set_level( log_warning );
00071       else if (level == "verbose")
00072   logger.set_level( log_verbose );
00073       else
00074   logger.set_level( m_arguments.get_integer("--log-level") );
00075     }
00076 
00077 } // application::application()
00078 
00079 /*----------------------------------------------------------------------------*/
00083 claw::application::~application()
00084 {
00085   logger.clear();
00086 } // application::~application()

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1