Merge branch 'logger' into trikiSA

This commit is contained in:
LPTK 2013-06-13 16:16:16 +02:00
commit 1e38346b1d
3 changed files with 177 additions and 121 deletions

View file

@ -7,50 +7,75 @@
#include <fstream>
#include <sstream>
#include <string>
#include <cassert>
//-----------------------------------------------------------------------------
static void test();
int main(int ac, char** av)
{
eoParser parser(ac, av);
if (parser.userNeedsHelp())
{
parser.printHelp(std::cout);
exit(1);
}
{
parser.printHelp(std::cout);
exit(1);
}
make_help(parser);
make_verbose(parser);
test();
return 0;
}
static void test()
{
eo::log << eo::setlevel(eo::debug);
eo::log << eo::warnings;
eo::log << "We are writing on the default output stream" << std::endl;
//eo::log << eo::file("test.txt") << "In FILE" << std::endl;
{
eo::log.redirect("logtest.txt");
eo::log << "In FILE" << std::endl;
std::ofstream ofs("logtest2.txt"); // closed and destroyed at the en of the scope
eo::log.addRedirect(ofs);
eo::log << "In FILE 2" << std::endl;
eo::log.removeRedirect(ofs); // must be removed because the associated stream is closed
}
std::ofstream ofs("logtest.txt");
//eo::log << ofs << "In FILE" << std::endl;
eo::log.redirect(ofs);
eo::log << "In FILE" << std::endl;
eo::log.redirect("logtest2.txt");
eo::log << "In FILE 2" << std::endl;
std::ifstream ifs("logtest2.txt"); // stream to logtest2.txt is closed, we can start reading
std::string line;
assert(std::getline(ifs, line));
assert(line == "In FILE 2");
assert(!std::getline(ifs, line));
std::ostringstream oss;
//eo::log << oss << "In STRINGSTREAM";
eo::log.redirect(oss);
eo::log << oss << "In STRINGSTREAM";
eo::log.addRedirect(oss);
eo::log << "In STRINGSTREAM";
//ofs << oss;
std::cout << "Content of ostringstream: " << oss.str() << std::endl;
assert(oss.str() == "In STRINGSTREAM");
//eo::log << std::cout << "on COUT" << std::endl;
eo::log.redirect(std::cout);
eo::log.redirect(std::cout); // removes all previously redirected streams; closes the file logtest.txt
eo::log << "on COUT" << std::endl;
ifs.close();
ifs.open("logtest.txt");
assert(std::getline(ifs, line));
assert(line == "In FILE");
assert(std::getline(ifs, line));
assert(line == "In FILE 2");
assert(std::getline(ifs, line));
assert(line == "In STRINGSTREAM");
assert(!std::getline(ifs, line));
eo::log << eo::setlevel("errors");
eo::log << eo::setlevel(eo::errors);
@ -65,9 +90,8 @@ int main(int ac, char** av)
eo::log << std::endl;
eo::log << eo::debug << 4 << ')'
<< "4) in debug mode\n";
return 0;
<< "4) in debug mode\n";
}
//-----------------------------------------------------------------------------