Commit be0fa4c4fabc542b911b4e4047cd1c8569596879
1 parent
47feef3a
Exists in
master
QLogger alterado para criar diretório caso seja passado um diretório não existen…
…te em addDestination.
Showing
2 changed files
with
23 additions
and
6 deletions
Show diff stats
cacic-teste/testcacic.cpp
@@ -266,16 +266,16 @@ void CTestCacic::testColeta() | @@ -266,16 +266,16 @@ void CTestCacic::testColeta() | ||
266 | void CTestCacic::testLogger() | 266 | void CTestCacic::testLogger() |
267 | { | 267 | { |
268 | QLogger::QLoggerManager *logManager = QLogger::QLoggerManager::getInstance(); | 268 | QLogger::QLoggerManager *logManager = QLogger::QLoggerManager::getInstance(); |
269 | - logManager->addDestination("./log.txt","teste",QLogger::DebugLevel); | 269 | + logManager->addDestination("log.txt","teste",QLogger::DebugLevel); |
270 | 270 | ||
271 | - QLogger::QLog_Debug("teste", "Teste do módulo logger."); | 271 | + QLogger::QLog_Debug("teste", "Teste do modulo logger."); |
272 | 272 | ||
273 | - QFile logFile("./log.txt"); | 273 | + QFile logFile("log.txt"); |
274 | if(logFile.exists()) logFile.open(QIODevice::ReadOnly); | 274 | if(logFile.exists()) logFile.open(QIODevice::ReadOnly); |
275 | 275 | ||
276 | QVERIFY(logManager && | 276 | QVERIFY(logManager && |
277 | logFile.exists() && | 277 | logFile.exists() && |
278 | - logFile.readLine().contains("Teste do módulo logger.") | 278 | + logFile.readLine().contains("Teste do modulo logger.") |
279 | ); | 279 | ); |
280 | 280 | ||
281 | logManager->closeLogger(); | 281 | logManager->closeLogger(); |
src/QLogger.cpp
@@ -113,6 +113,7 @@ namespace QLogger | @@ -113,6 +113,7 @@ namespace QLogger | ||
113 | bool QLoggerManager::addDestination(const QString &fileDest, const QStringList &modules, LogLevel level) | 113 | bool QLoggerManager::addDestination(const QString &fileDest, const QStringList &modules, LogLevel level) |
114 | { | 114 | { |
115 | QLoggerWriter *log; | 115 | QLoggerWriter *log; |
116 | + | ||
116 | foreach (QString module, modules) | 117 | foreach (QString module, modules) |
117 | { | 118 | { |
118 | if (!moduleDest.contains(module)) | 119 | if (!moduleDest.contains(module)) |
@@ -139,13 +140,29 @@ namespace QLogger | @@ -139,13 +140,29 @@ namespace QLogger | ||
139 | 140 | ||
140 | void QLoggerWriter::write(const QString &module, const QString &message) | 141 | void QLoggerWriter::write(const QString &module, const QString &message) |
141 | { | 142 | { |
143 | + QString originalDir = QDir::currentPath(); | ||
142 | QString _fileName = m_fileDestination; | 144 | QString _fileName = m_fileDestination; |
143 | 145 | ||
144 | int MAX_SIZE = 1024 * 1024; | 146 | int MAX_SIZE = 1024 * 1024; |
145 | 147 | ||
148 | + | ||
149 | + QStringList fileDestSplit = _fileName.split("/"); | ||
150 | + QString dirDest; | ||
151 | + | ||
152 | + for(int i = 0 ; i < fileDestSplit.size() ; ++i ) | ||
153 | + { | ||
154 | + if( !(i == fileDestSplit.size() - 1) ) // last fileDestSplit element | ||
155 | + { | ||
156 | + dirDest.append(fileDestSplit[i] + "/"); | ||
157 | + } | ||
158 | + } | ||
159 | + | ||
146 | QDir dir(QDir::currentPath()); | 160 | QDir dir(QDir::currentPath()); |
147 | - if (!dir.exists("logs")) | ||
148 | - dir.mkdir("logs"); | 161 | + |
162 | + if (!dir.exists(dirDest)) | ||
163 | + dir.mkdir(dirDest); | ||
164 | + | ||
165 | +// dir.cd(dirDest); | ||
149 | 166 | ||
150 | QFile file(_fileName); | 167 | QFile file(_fileName); |
151 | QString toRemove = _fileName.section('.',-1); | 168 | QString toRemove = _fileName.section('.',-1); |