Changeset ef9dff6
- Timestamp:
- Jul 14, 2014, 8:37:03 PM (11 years ago)
- Children:
- 0ab195
- Parents:
- ca940b
- git-author:
- Frederik Heber <heber@…> (06/19/14 16:26:39)
- git-committer:
- Frederik Heber <heber@…> (07/14/14 20:37:03)
- Location:
- src
- Files:
-
- 8 edited
-
CodePatterns/errorlogger.hpp (modified) (2 diffs)
-
CodePatterns/logger.hpp (modified) (2 diffs)
-
Helpers/errorlogger.cpp (modified) (6 diffs)
-
Helpers/logger.cpp (modified) (6 diffs)
-
Helpers/unittests/LogUnitTest.cpp (modified) (3 diffs)
-
Helpers/unittests/LogUnitTest.hpp (modified) (2 diffs)
-
Helpers/unittests/Makefile.am (modified) (1 diff)
-
Helpers/unittests/stubs/loggerStub.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodePatterns/errorlogger.hpp
rca940b ref9dff6 26 26 public : 27 27 static ostream *nix; 28 static ostream *out; 29 static ostream *defaultout; 28 30 static int verbosity; 29 31 … … 31 33 static void setVerbosity(int verbosityLevel); 32 34 static int getVerbosity(); 35 static void setOutputStream(ostream *_newout); 33 36 34 37 protected: -
src/CodePatterns/logger.hpp
rca940b ref9dff6 26 26 public : 27 27 static ostream *nix; 28 static ostream *out; 29 static ostream *defaultout; 28 30 static int verbosity; 29 31 … … 31 33 static void setVerbosity(int verbosityLevel); 32 34 static int getVerbosity(); 35 static void setOutputStream(ostream *_newout); 33 36 34 37 protected: -
src/Helpers/errorlogger.cpp
rca940b ref9dff6 28 28 int errorLogger::verbosity = 2; 29 29 ostream* errorLogger::nix = NULL; 30 ostream* errorLogger::defaultout = NULL; 31 ostream* errorLogger::out = NULL; 30 32 31 33 /** … … 37 39 { 38 40 nix = new ofstream("/dev/null"); 41 defaultout = &cerr; 42 out = defaultout; 39 43 }; 40 44 … … 45 49 { 46 50 delete nix; 51 out = NULL; // we are not responsible if out got changed 52 defaultout = NULL; // do not delete cerr 47 53 } 48 54 … … 67 73 return verbosity; 68 74 } 75 76 /** Sets a new output stream. 77 * 78 * \param _newout new output stream, if NULL we set to defaultout 79 */ 80 void errorLogger::setOutputStream(ostream *_newout) 81 { 82 if(_newout != NULL) 83 out = _newout; 84 else 85 out = defaultout; 86 } 87 69 88 70 89 /** … … 95 114 break; 96 115 } 97 v.print( cerr);98 return cerr;116 v.print(*errorLogger::out); 117 return *errorLogger::out; 99 118 } else 100 119 return *l.nix; … … 117 136 break; 118 137 } 119 v.print( cerr);120 return cerr;138 v.print(*errorLogger::out); 139 return *errorLogger::out; 121 140 } else 122 141 return *l->nix; -
src/Helpers/logger.cpp
rca940b ref9dff6 29 29 int logger::verbosity = 2; 30 30 ostream* logger::nix = NULL; 31 ostream* logger::defaultout = NULL; 32 ostream* logger::out = NULL; 31 33 32 34 /** … … 38 40 { 39 41 nix = new ofstream("/dev/null"); 42 defaultout = &cout; 43 out = defaultout; 40 44 }; 41 45 … … 46 50 { 47 51 delete nix; 52 out = NULL; // we are not responsible if out got changed 53 defaultout = NULL; // do not delete cout 48 54 } 49 55 … … 69 75 } 70 76 77 /** Sets a new output stream. 78 * 79 * \param _newout new output stream, if NULL we set to defaultout 80 */ 81 void logger::setOutputStream(ostream *_newout) 82 { 83 if(_newout != NULL) 84 out = _newout; 85 else 86 out = defaultout; 87 } 88 71 89 /** 72 90 * Operator for the Binary(arg) call. … … 83 101 l.nix->clear(); 84 102 if (v.DoOutput(verbosityLevel)) { 85 v.print( cout);86 return cout;103 v.print(*logger::out); 104 return *logger::out; 87 105 } else 88 106 return *l.nix; … … 93 111 l->nix->clear(); 94 112 if (v.DoOutput(verbosityLevel)) { 95 v.print( cout);96 return cout;113 v.print(*logger::out); 114 return *logger::out; 97 115 } else 98 116 return *l->nix; -
src/Helpers/unittests/LogUnitTest.cpp
rca940b ref9dff6 39 39 void LogTest::setUp() 40 40 { 41 } ;41 } 42 42 43 43 void LogTest::tearDown() … … 45 45 logger::purgeInstance(); 46 46 errorLogger::purgeInstance(); 47 } ;47 } 48 48 49 49 /** … … 70 70 CPPUNIT_ASSERT(!DoLog(4)); 71 71 CPPUNIT_ASSERT(!DoeLog(4)); 72 }; 72 } 73 74 /** 75 * UnitTest for log() 76 */ 77 void LogTest::newOutputTest() 78 { 79 // check whether redirecting output works 80 std::stringstream teststream; 81 { 82 Log().setOutputStream(&teststream); 83 logger::getInstance().setVerbosity(2); 84 Log() << Verbose(0) << std::string("test"); 85 // DoLog(0) && (Log() << Verbose(0) << "test" << endl); 86 CPPUNIT_ASSERT_EQUAL( std::string("test"), teststream.str() ); 87 Log().setOutputStream(NULL); // go to default, as stringstream is destroyed 88 } 89 // redirect to NULL changes to cout 90 teststream.str(""); 91 { 92 DoLog(0) && (Log() << Verbose(0) << "test" << endl); 93 CPPUNIT_ASSERT_EQUAL( std::string(""), teststream.str() ); 94 } 95 } -
src/Helpers/unittests/LogUnitTest.hpp
rca940b ref9dff6 20 20 CPPUNIT_TEST_SUITE( LogTest) ; 21 21 CPPUNIT_TEST ( logTest ); 22 CPPUNIT_TEST ( newOutputTest ); 22 23 CPPUNIT_TEST_SUITE_END(); 23 24 … … 25 26 void setUp(); 26 27 void tearDown(); 28 void newOutputTest(); 27 29 28 30 void logTest(); -
src/Helpers/unittests/Makefile.am
rca940b ref9dff6 77 77 LogUnitTest_SOURCES = UnitTestMain.cpp \ 78 78 ../Helpers/unittests/LogUnitTest.cpp \ 79 ../Helpers/unittests/LogUnitTest.hpp \ 80 ../Helpers/unittests/stubs/errorloggerStub.cpp \ 81 ../Helpers/unittests/stubs/loggerStub.cpp 79 ../Helpers/unittests/LogUnitTest.hpp 82 80 nodist_LogUnitTest_SOURCES = \ 83 81 $(top_srcdir)/src/CodePatterns/Assert.hpp \ -
src/Helpers/unittests/stubs/loggerStub.cpp
rca940b ref9dff6 26 26 int logger::verbosity = 2; 27 27 ostream* logger::nix = NULL; 28 ostream* logger::defaultout = NULL; 29 ostream* logger::out = NULL; 28 30 29 31 /** … … 35 37 { 36 38 nix = new stringstream; 39 defaultout = new stringstream; 40 out = defaultout; 37 41 }; 38 42 … … 43 47 { 44 48 delete nix; 49 delete defaultout; 50 out = NULL; 45 51 } 46 52 … … 65 71 } 66 72 73 /** Sets a new output stream. 74 * 75 * \param _newout new output stream, if NULL we set to defaultout 76 */ 77 void logger::setOutputStream(ostream *_newout) 78 { 79 if(_newout != NULL) 80 out = _newout; 81 else 82 out = defaultout; 83 } 84 67 85 /** 68 86 * Operator for the Binary(arg) call.
Note:
See TracChangeset
for help on using the changeset viewer.
