Changeset 2c11c1 for src/Patterns/Observer/ObserverLog.cpp
- Timestamp:
- Dec 13, 2011, 10:45:00 AM (14 years ago)
- Children:
- d85532
- Parents:
- 40f2e6
- git-author:
- Frederik Heber <heber@…> (12/02/11 13:05:49)
- git-committer:
- Frederik Heber <heber@…> (12/13/11 10:45:00)
- File:
-
- 1 edited
-
src/Patterns/Observer/ObserverLog.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer/ObserverLog.cpp
r40f2e6 r2c11c1 20 20 #include "MemDebug.hpp" 21 21 22 #include <fstream> 23 #include <iostream> 24 #include <sstream> 25 22 26 #include "ObserverLog.hpp" 27 #include "Singleton_impl.hpp" 23 28 29 std::ostream* ObserverLog::nullstream = NULL; 30 std::ostream* ObserverLog::outstream = NULL; 24 31 25 ObserverLog::ObserverLog() : 26 count (0) 32 ObserverLog::ObserverLog() 33 { 34 nullstream = new std::ofstream("/dev/null"); 35 outstream = nullstream; 36 } 37 38 ObserverLog::~ObserverLog() 39 { 40 outstream = NULL; 41 delete nullstream; 42 } 43 44 /** Constructor of class Log. 45 * 46 * Log is just a tiny helper to bring the log message to screen and to the 47 * ObserverLog's log. 48 * 49 * @param _callback_ref 50 */ 51 ObserverLog::Log::Log(ObserverLog *_callback_ref) : 52 callback_ref(_callback_ref) 27 53 {} 28 54 29 ObserverLog::~ObserverLog(){} 55 /** Destructor of class Log. 56 * 57 * Prints to both ObserverLog::log and to ObserverLog::outstream. 58 * 59 */ 60 ObserverLog::Log::~Log() 61 { 62 callback_ref->log << log.str() << std::endl; 63 *callback_ref->outstream << log.str() << std::endl; 30 64 31 std::string ObserverLog::getLog(){return log.str();} 65 callback_ref = NULL; 66 } 67 68 void ObserverLog::disableLogging() 69 { 70 outstream = nullstream; 71 } 72 73 void ObserverLog::enableLogging() 74 { 75 outstream = &std::cout; 76 } 77 78 std::string ObserverLog::getLog() { return log.str(); } 32 79 33 80 std::string ObserverLog::getName(void* obj){ … … 57 104 } 58 105 59 std::stringstream &ObserverLog::addMessage(int depth){ 106 /** Obtain Log reference to place another message (line) in log. 107 * 108 * \warning Don't append std::endl to the message, won't work and is done 109 * automatically. 110 * 111 * @param depth depth (indenting) of the message 112 * @return ref to Log class which can be ostreamed to 113 */ 114 boost::shared_ptr<ObserverLog::Log> ObserverLog::addMessage(int depth){ 115 boost::shared_ptr<ObserverLog::Log> L(new Log(this)); 60 116 for(int i=depth;i--;) 61 log << " ";62 return log;117 L->log << " "; 118 return L; 63 119 } 64 120 65 // The log needs to exist fairly early, so we make it construct on first use, 66 // and never destroy it 67 ObserverLog &observerLog(){ 68 // yes, this memory is never freed... we need it around for the whole programm, 69 // so no freeing is possible 70 static ObserverLog *theLog = Memory::ignore(new ObserverLog()); 71 return *theLog; 121 ObserverLog &observerLog() 122 { 123 return ObserverLog::getInstance(); 72 124 } 73 125 126 CONSTRUCT_SINGLETON(ObserverLog)
Note:
See TracChangeset
for help on using the changeset viewer.
