Changeset 9544 for code/branches/testing/src/libraries
- Timestamp:
- Mar 11, 2013, 11:13:21 PM (12 years ago)
- Location:
- code/branches/testing/src/libraries/util/output
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/testing/src/libraries/util/output/LogWriter.cc
r9540 r9544 39 39 #include "OutputManager.h" 40 40 #include "MemoryWriter.h" 41 #include "util/Convert.h" 41 42 42 43 namespace orxonox 43 44 { 45 static const int MAX_ARCHIVED_FILES = 9; 46 44 47 /** 45 48 @brief Constructor, initializes the desired output levels and the name and path of the log-file, and opens the log-file. … … 82 85 void LogWriter::openFile() 83 86 { 87 // archive the old log file 88 this->archive(); 89 84 90 // open the file 85 91 this->file_.open(this->getPath().c_str(), std::fstream::out); … … 102 108 this->file_.close(); 103 109 } 110 } 111 112 /** 113 * @brief Archives old copies of the log file by adding increasing numbers to the filename. 114 */ 115 void LogWriter::archive(int index) 116 { 117 std::string oldPath = this->getArchivedPath(index); 118 119 // see if the file already exists, otherwise return 120 std::ifstream stream(oldPath.c_str()); 121 bool exists = stream.is_open(); 122 stream.close(); 123 124 if (!exists) 125 return; 126 127 if (index < MAX_ARCHIVED_FILES) 128 { 129 // increment the index and archive the file with the next higher index 130 this->archive(++index); 131 132 // create the new path based on the incremented index 133 std::string newPath = this->getArchivedPath(index); 134 135 // move the file 136 std::rename(oldPath.c_str(), newPath.c_str()); 137 } 138 else 139 { 140 // delete the file 141 std::remove(oldPath.c_str()); 142 } 143 } 144 145 /** 146 * @brief Returns the path for archived copies of the logfile (based on the archive index) 147 */ 148 std::string LogWriter::getArchivedPath(int index) const 149 { 150 std::string path = this->getPath(); 151 if (index > 0) 152 path += '.' + multi_cast<std::string>(index); 153 return path; 104 154 } 105 155 -
code/branches/testing/src/libraries/util/output/LogWriter.h
r9542 r9544 76 76 void closeFile(); 77 77 78 void archive(int index = 0); 79 std::string getArchivedPath(int index) const; 80 78 81 std::string filename_; ///< The name of the log-file (without directory) 79 82 std::string directory_; ///< The directory where the log-file resided (without file-name)
Note: See TracChangeset
for help on using the changeset viewer.