Changeset 8517 for code/branches/unity_build
- Timestamp:
- May 20, 2011, 5:18:08 AM (14 years ago)
- Location:
- code/branches/unity_build/src/libraries
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/unity_build/src/libraries/core/Core.cc
r8423 r8517 168 168 RegisterRootObject(Core); 169 169 this->setConfigValues(); 170 // Rewrite the log file with the correct log levels 171 OutputHandler::getInstance().rewriteLogFile(); 170 172 171 173 #if !defined(ORXONOX_PLATFORM_APPLE) && !defined(ORXONOX_USE_WINMAIN) … … 240 242 SetConfigValueExternal(softDebugLevelLogFile_, "OutputHandler", "softDebugLevelLogFile", defaultLevelLogFile) 241 243 .description("The maximum level of debug output shown in the log file"); 242 OutputHandler::getInstance().setSoftDebugLevel( OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_);244 OutputHandler::getInstance().setSoftDebugLevel("LogFile", this->softDebugLevelLogFile_); 243 245 244 246 SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun()) -
code/branches/unity_build/src/libraries/util/OutputHandler.cc
r8516 r8517 69 69 */ 70 70 LogFileWriter() 71 : OutputListener( OutputHandler::logFileOutputListenerName_s)71 : OutputListener("LogFile") 72 72 { 73 73 // Get path for a temporary file … … 85 85 timeinfo = localtime(&rawtime); 86 86 87 this->logFile_.open(this->logFilename_.c_str(), std::fstream::out); 88 this->logFile_ << "Started log on " << asctime(timeinfo) << std::endl; 89 this->logFile_.flush(); 90 91 this->outputStream_ = &this->logFile_; 87 this->openFile(); 88 if (this->logFile_.is_open()) 89 { 90 this->logFile_ << "Started log on " << asctime(timeinfo) << std::endl; 91 this->logFile_.flush(); 92 } 92 93 } 93 94 … … 95 96 ~LogFileWriter() 96 97 { 97 this->logFile_ << "Closed log" << std::endl; 98 this->logFile_.close(); 98 if (this->logFile_.is_open()) 99 { 100 this->logFile_ << "Closed log" << std::endl; 101 this->logFile_.close(); 102 } 99 103 } 100 104 … … 102 106 void setLogPath(const std::string& path) 103 107 { 104 this->logFile_.close(); 105 // Read old file into a buffer 106 std::ifstream old(this->logFilename_.c_str()); 108 if (this->logFile_.is_open()) 109 this->logFile_.close(); 110 111 // Open the new file 107 112 this->logFilename_ = path + logFileBaseName_g; 108 // Open the new file and feed it the content of the old one 113 this->openFile(); 114 } 115 116 //! Erases the log file 117 void clearFile() 118 { 119 if (this->logFile_.is_open()) 120 { 121 this->logFile_.close(); 122 this->openFile(); 123 } 124 } 125 126 private: 127 void openFile() 128 { 109 129 this->logFile_.open(this->logFilename_.c_str(), std::fstream::out); 110 this->logFile_ << old.rdbuf(); 111 this->logFile_.flush(); 112 old.close(); 113 } 114 115 private: 130 131 if (this->logFile_.is_open()) 132 this->outputStream_ = &this->logFile_; 133 else 134 { 135 COUT(2) << "Warning: Failed to open log file. File logging disabled." << std::endl; 136 this->outputStream_ = NULL; 137 } 138 } 139 116 140 std::ofstream logFile_; //!< File handle for the log file 117 141 std::string logFilename_; //!< Filename of the log file … … 185 209 ///// OutputHandler ///// 186 210 ///////////////////////// 187 const std::string OutputHandler::logFileOutputListenerName_s = "logFile"; 188 int OutputHandler::softDebugLevel_s = hardDebugLevel; 211 int OutputHandler::softDebugLevel_s = hardDebugLevel; 189 212 190 213 //! Creates the LogFileWriter and the MemoryLogWriter … … 259 282 { 260 283 this->logFile_->setLogPath(path); 284 this->rewriteLogFile(); 285 } 286 287 void OutputHandler::rewriteLogFile() 288 { 289 logFile_->clearFile(); 290 291 if (logFile_->outputStream_ == NULL) 292 return; 293 294 for (OutputVector::const_iterator it = this->getOutput().begin(); it != this->getOutput().end(); ++it) 295 { 296 if (it->first <= logFile_->softDebugLevel_) 297 (*logFile_->outputStream_) << it->second; 298 } 299 logFile_->outputStream_->flush(); 261 300 } 262 301 -
code/branches/unity_build/src/libraries/util/OutputHandler.h
r8516 r8517 133 133 //! Set the log path once the program has been properly initialised 134 134 void setLogPath(const std::string& path); 135 /** Rewrites the log file (completely respects the current debug level). 136 Once disableMemoryLog() has been called, this function will do nothing. 137 */ 138 void rewriteLogFile(); 139 135 140 //! Disables the std::cout stream for output 136 141 void disableCout(); … … 211 216 //! Dummy operator required by Debug.h for the ternary operator 212 217 inline operator int() const { return 0; } 213 214 //! Name of the OutputListener that writes to the log file215 static const std::string logFileOutputListenerName_s;216 218 217 219 private:
Note: See TracChangeset
for help on using the changeset viewer.