ticker #11 fixed: Merge eoParser and eoParserLogger
This commit is contained in:
parent
e103f4f29e
commit
7d9151e2f4
5 changed files with 103 additions and 189 deletions
|
|
@ -12,24 +12,24 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
|||
SET(EOUTILS_LIB_OUTPUT_PATH ${EO_BINARY_DIR}/lib)
|
||||
SET(LIBRARY_OUTPUT_PATH ${EOUTILS_LIB_OUTPUT_PATH})
|
||||
|
||||
SET (EOUTILS_SOURCES eoData.cpp
|
||||
eoFileMonitor.cpp
|
||||
eoGnuplot.cpp
|
||||
eoGnuplot1DMonitor.cpp
|
||||
eoGnuplot1DSnapshot.cpp
|
||||
eoIntBounds.cpp
|
||||
eoParser.cpp
|
||||
eoRealBounds.cpp
|
||||
eoRNG.cpp
|
||||
eoState.cpp
|
||||
eoOStreamMonitor.cpp
|
||||
eoUpdater.cpp
|
||||
make_help.cpp
|
||||
pipecom.cpp
|
||||
eoLogger.cpp
|
||||
eoParserLogger.cpp
|
||||
eoParallel.cpp)
|
||||
|
||||
SET(EOUTILS_SOURCES
|
||||
eoData.cpp
|
||||
eoFileMonitor.cpp
|
||||
eoGnuplot.cpp
|
||||
eoGnuplot1DMonitor.cpp
|
||||
eoGnuplot1DSnapshot.cpp
|
||||
eoIntBounds.cpp
|
||||
eoParser.cpp
|
||||
eoRealBounds.cpp
|
||||
eoRNG.cpp
|
||||
eoState.cpp
|
||||
eoOStreamMonitor.cpp
|
||||
eoUpdater.cpp
|
||||
make_help.cpp
|
||||
pipecom.cpp
|
||||
eoLogger.cpp
|
||||
eoParallel.cpp
|
||||
)
|
||||
|
||||
ADD_LIBRARY(eoutils STATIC ${EOUTILS_SOURCES})
|
||||
INSTALL(TARGETS eoutils ARCHIVE DESTINATION lib COMPONENT libraries)
|
||||
|
|
|
|||
|
|
@ -37,19 +37,20 @@ Authors:
|
|||
#include <cstdio> // used to define EOF
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <locale>
|
||||
|
||||
#include "eoLogger.h"
|
||||
|
||||
eoLogger eo::log;
|
||||
eoLogger::eoLogger() :
|
||||
std::ostream(&_obuf),
|
||||
|
||||
eoLogger::eoLogger()
|
||||
: std::ostream(&_obuf),
|
||||
_selectedLevel(eo::progress), _contextLevel(eo::quiet),
|
||||
_fd(2), _obuf(_fd, _contextLevel, _selectedLevel)
|
||||
_verbose("quiet", "verbose", "Set the verbose level", 'v'),
|
||||
_printVerboseLevels(false, "print-verbose-levels", "Print verbose levels", 'l'),
|
||||
_output("", "output", "Redirect a standard output to a file", 'o'),
|
||||
|
||||
_selectedLevel(eo::progress),
|
||||
_contextLevel(eo::quiet),
|
||||
_fd(2),
|
||||
_obuf(_fd, _contextLevel, _selectedLevel)
|
||||
{
|
||||
_standard_io_streams[&std::cout] = 1;
|
||||
_standard_io_streams[&std::clog] = 2;
|
||||
|
|
@ -71,18 +72,56 @@ eoLogger::~eoLogger()
|
|||
if (_fd > 2) { ::close(_fd); }
|
||||
}
|
||||
|
||||
std::string eoLogger::className() const
|
||||
void eoLogger::_createParameters( eoParser& parser )
|
||||
{
|
||||
//------------------------------------------------------------------
|
||||
// we are saying to eoParser to create the parameters created above.
|
||||
//------------------------------------------------------------------
|
||||
|
||||
std::string section("Logger");
|
||||
parser.processParam(_verbose, section);
|
||||
parser.processParam(_printVerboseLevels, section);
|
||||
parser.processParam(_output, section);
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// we're gonna redirect the log to the given filename if -o is used.
|
||||
//------------------------------------------------------------------
|
||||
|
||||
if ( ! _output.value().empty() )
|
||||
{
|
||||
eo::log << eo::file( _output.value() );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// // we're gonna print the list of levels if -l parameter is used.
|
||||
//------------------------------------------------------------------
|
||||
|
||||
if ( _printVerboseLevels.value() )
|
||||
{
|
||||
eo::log.printLevels();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
}
|
||||
|
||||
std::string eoLogger::className() const
|
||||
{
|
||||
return ("eoLogger");
|
||||
}
|
||||
|
||||
void eoLogger::addLevel(std::string name, eo::Levels level)
|
||||
void eoLogger::addLevel(std::string name, eo::Levels level)
|
||||
{
|
||||
_levels[name] = level;
|
||||
_sortedLevels.push_back(name);
|
||||
}
|
||||
|
||||
void eoLogger::printLevels() const
|
||||
void eoLogger::printLevels() const
|
||||
{
|
||||
std::cout << "Available verbose levels:" << std::endl;
|
||||
|
||||
|
|
@ -95,25 +134,25 @@ void eoLogger::printLevels() const
|
|||
::exit(0);
|
||||
}
|
||||
|
||||
eoLogger& operator<<(eoLogger& l, const eo::Levels lvl)
|
||||
eoLogger& operator<<(eoLogger& l, const eo::Levels lvl)
|
||||
{
|
||||
l._contextLevel = lvl;
|
||||
return l;
|
||||
}
|
||||
|
||||
eoLogger& operator<<(eoLogger& l, eo::file f)
|
||||
eoLogger& operator<<(eoLogger& l, eo::file f)
|
||||
{
|
||||
l._fd = ::open(f._f.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||
return l;
|
||||
}
|
||||
|
||||
eoLogger& operator<<(eoLogger& l, eo::setlevel v)
|
||||
eoLogger& operator<<(eoLogger& l, eo::setlevel v)
|
||||
{
|
||||
l._selectedLevel = (v._lvl < 0 ? l._levels[v._v] : v._lvl);
|
||||
return l;
|
||||
}
|
||||
|
||||
eoLogger& operator<<(eoLogger& l, std::ostream& os)
|
||||
eoLogger& operator<<(eoLogger& l, std::ostream& os)
|
||||
{
|
||||
if (l._standard_io_streams.find(&os) != l._standard_io_streams.end())
|
||||
{
|
||||
|
|
@ -128,7 +167,7 @@ eoLogger::outbuf::outbuf(const int& fd,
|
|||
: _fd(fd), _contextLevel(contexlvl), _selectedLevel(selectedlvl)
|
||||
{}
|
||||
|
||||
int eoLogger::outbuf::overflow(int_type c)
|
||||
int eoLogger::outbuf::overflow(int_type c)
|
||||
{
|
||||
if (_selectedLevel >= _contextLevel)
|
||||
{
|
||||
|
|
@ -141,7 +180,7 @@ int eoLogger::outbuf::overflow(int_type c)
|
|||
return c;
|
||||
}
|
||||
|
||||
namespace eo
|
||||
namespace eo
|
||||
{
|
||||
file::file(const std::string f)
|
||||
: _f(f)
|
||||
|
|
@ -155,3 +194,13 @@ namespace eo
|
|||
: _v(std::string("")), _lvl(lvl)
|
||||
{}
|
||||
}
|
||||
|
||||
//! make_verbose gets level of verbose and sets it in eoLogger
|
||||
void make_verbose(eoParser& parser)
|
||||
{
|
||||
eo::log._createParameters( parser );
|
||||
|
||||
eo::log << eo::setlevel(eo::log._verbose.value());
|
||||
}
|
||||
|
||||
eoLogger eo::log;
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@ Caner Candan <caner.candan@thalesgroup.com>
|
|||
\code
|
||||
#include <iostream>
|
||||
#include <utils/eoLogger.h>
|
||||
#include <utils/eoParserLogger.h>
|
||||
#include <utils/eoParser.h>
|
||||
|
||||
int main(int ac, char** av)
|
||||
{
|
||||
// We are declaring first an overload of eoParser class using Logger
|
||||
// component.
|
||||
eoParserLogger parser(ac, av);
|
||||
eoParser parser(ac, av);
|
||||
|
||||
// This call is important to allow -v parameter to change user level.
|
||||
make_verbose(parser);
|
||||
|
|
@ -88,15 +88,15 @@ Caner Candan <caner.candan@thalesgroup.com>
|
|||
*/
|
||||
|
||||
#ifndef eoLogger_h
|
||||
# define eoLogger_h
|
||||
#define eoLogger_h
|
||||
|
||||
# include <map>
|
||||
# include <vector>
|
||||
# include <string>
|
||||
# include <iosfwd>
|
||||
|
||||
# include "eoObject.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
|
||||
#include "eoObject.h"
|
||||
#include "eoParser.h"
|
||||
|
||||
namespace eo
|
||||
{
|
||||
|
|
@ -168,6 +168,9 @@ public:
|
|||
protected:
|
||||
void addLevel(std::string name, eo::Levels level);
|
||||
|
||||
private:
|
||||
void _createParameters( eoParser& );
|
||||
|
||||
private:
|
||||
/**
|
||||
* outbuf
|
||||
|
|
@ -213,6 +216,12 @@ public:
|
|||
friend eoLogger& operator<<(eoLogger&, std::ostream&);
|
||||
|
||||
private:
|
||||
friend void make_verbose(eoParser&);
|
||||
|
||||
eoValueParam<std::string> _verbose;
|
||||
eoValueParam<bool> _printVerboseLevels;
|
||||
eoValueParam<std::string> _output;
|
||||
|
||||
/**
|
||||
* _selectedLevel is the member storing verbose level setted by the user thanks to operator()
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
|
||||
(c) Thales group, 2010
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; version 2 of the license.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this library; if not, write to the Free Software Foundation, Inc., 59
|
||||
Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: http://eodev.sourceforge.net
|
||||
|
||||
Authors:
|
||||
Johann Dreo <johann.dreo@thalesgroup.com>
|
||||
Caner Candan <caner.candan@thalesgroup.com>
|
||||
|
||||
*/
|
||||
|
||||
#include "eoParserLogger.h"
|
||||
|
||||
eoParserLogger::eoParserLogger(unsigned _argc, char** _argv,
|
||||
std::string _programDescription /*= ""*/
|
||||
,
|
||||
std::string _lFileParamName /*= "param-file"*/,
|
||||
char _shortHand /*= 'p'*/)
|
||||
: eoParser(_argc, _argv, _programDescription, _lFileParamName, _shortHand),
|
||||
_verbose("quiet", "verbose", "Set the verbose level", 'v'),
|
||||
_printVerboseLevels(false, "print-verbose-levels", "Print verbose levels", 'l'),
|
||||
_output("", "output", "Redirect a standard output to a file", 'o')
|
||||
{
|
||||
//------------------------------------------------------------------
|
||||
// we are saying to eoParser to create the parameters created above.
|
||||
//------------------------------------------------------------------
|
||||
|
||||
processParam(_verbose);
|
||||
processParam(_printVerboseLevels);
|
||||
processParam(_output);
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// we're gonna redirect the log to the given filename if -o is used.
|
||||
//------------------------------------------------------------------
|
||||
|
||||
if ( ! _output.value().empty() )
|
||||
{
|
||||
eo::log << eo::file( _output.value() );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// // we're gonna print the list of levels if -l parameter is used.
|
||||
//------------------------------------------------------------------
|
||||
|
||||
if ( _printVerboseLevels.value() )
|
||||
{
|
||||
eo::log.printLevels();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
eoParserLogger::~eoParserLogger()
|
||||
{}
|
||||
|
||||
//! make_verbose gets level of verbose and sets it in eoLogger
|
||||
void make_verbose(eoParserLogger& _parser)
|
||||
{
|
||||
eo::log << eo::setlevel(_parser._verbose.value());
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
/*
|
||||
|
||||
(c) Thales group, 2010
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; version 2 of the license.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this library; if not, write to the Free Software Foundation, Inc., 59
|
||||
Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: http://eodev.sourceforge.net
|
||||
|
||||
Authors:
|
||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
Caner Candan <caner.candan@thalesgroup.com>
|
||||
*/
|
||||
|
||||
#ifndef EO_PARSER_LOGGER_H
|
||||
#define EO_PARSER_LOGGER_H
|
||||
|
||||
#include "eoParser.h"
|
||||
#include "eoLogger.h"
|
||||
|
||||
/**
|
||||
* A parser that use the advanced logging system (@see eoLogger)
|
||||
*
|
||||
* @ingroup Parameters
|
||||
* @ingroup Logging
|
||||
*/
|
||||
class eoParserLogger : public eoParser
|
||||
{
|
||||
public:
|
||||
eoParserLogger(unsigned _argc, char** _argv,
|
||||
std::string _programDescription = "",
|
||||
std::string _lFileParamName = "param-file",
|
||||
char _shortHand = 'p');
|
||||
~eoParserLogger();
|
||||
|
||||
private:
|
||||
friend void make_verbose(eoParserLogger&);
|
||||
eoValueParam<std::string> _verbose;
|
||||
eoValueParam<bool> _printVerboseLevels;
|
||||
eoValueParam<std::string> _output;
|
||||
};
|
||||
|
||||
void make_verbose(eoParserLogger&);
|
||||
|
||||
#endif // !EO_PARSER_LOGGER_H
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
Loading…
Add table
Add a link
Reference in a new issue