diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-11-13 19:58:04 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-11-13 19:58:04 +0300 |
commit | b7103fbcef86554476871ad363e2a6b3bad0b77e (patch) | |
tree | 263d71fdd32dbbc0026c10274b4d7fa54c30f25c | |
parent | bc6e0ea4d7042ad48164b8bad69bff02ca5f8a5a (diff) | |
download | mv-b7103fbcef86554476871ad363e2a6b3bad0b77e.tar.gz mv-b7103fbcef86554476871ad363e2a6b3bad0b77e.tar.bz2 mv-b7103fbcef86554476871ad363e2a6b3bad0b77e.tar.xz mv-b7103fbcef86554476871ad363e2a6b3bad0b77e.zip |
Change chat logs dirs format to yyyy-mm/dd/file.log.
-rw-r--r-- | src/chatlogger.cpp | 64 | ||||
-rw-r--r-- | src/chatlogger.h | 14 | ||||
-rw-r--r-- | src/client.cpp | 4 | ||||
-rw-r--r-- | src/net/ea/partyhandler.cpp | 1 |
4 files changed, 43 insertions, 40 deletions
diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index 067265138..0299a6fe3 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -40,11 +40,16 @@ #include "logger.h" #include "configuration.h" +#include "utils/mkdir.h" #include "utils/stringutils.h" #include "debug.h" -ChatLogger::ChatLogger() +ChatLogger::ChatLogger() : + mLogDir(""), + mBaseLogDir(""), + mServerName(""), + mLogFileName("") { } @@ -60,6 +65,7 @@ void ChatLogger::setLogFile(const std::string &logFilename) mLogFile.close(); mLogFile.open(logFilename.c_str(), std::ios_base::app); + mLogFileName = logFilename; if (!mLogFile.is_open()) { @@ -77,19 +83,19 @@ void ChatLogger::setLogDir(const std::string &logDir) DIR *dir = opendir(mLogDir.c_str()); if (!dir) - makeDir(mLogDir); + mkdir_r(mLogDir.c_str()); else closedir(dir); } void ChatLogger::log(std::string str) { - std::string dateStr = getDateString(); - if (!mLogFile.is_open() || dateStr != mLogDate) + std::string dateStr = getDir(); + std::string logFileName = strprintf("%s/#General.log", dateStr.c_str()); + if (!mLogFile.is_open() || logFileName != mLogFileName) { - mLogDate = dateStr; - setLogFile(strprintf("%s/%s/#General_%s.log", mLogDir.c_str(), - mServerName.c_str(), dateStr.c_str())); + setLogDir(dateStr); + setLogFile(logFileName); } str = removeColors(str); @@ -99,21 +105,21 @@ void ChatLogger::log(std::string str) void ChatLogger::log(std::string name, std::string str) { std::ofstream logFile; - logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), - mServerName.c_str(), secureName(name).c_str(), - getDateString().c_str()).c_str(), std::ios_base::app); + std::string dateStr = getDir(); + std::string logFileName = strprintf("%s/%s.log", + dateStr.c_str(), secureName(name).c_str()); - if (!logFile.is_open()) - return; + if (!mLogFile.is_open() || logFileName != mLogFileName) + { + setLogDir(dateStr); + setLogFile(logFileName); + } str = removeColors(str); - writeTo(logFile, str); - - if (logFile.is_open()) - logFile.close(); + writeTo(mLogFile, str); } -std::string ChatLogger::getDateString() const +std::string ChatLogger::getDir() const { std::string date; @@ -124,8 +130,11 @@ std::string ChatLogger::getDateString() const time (&rawtime); timeinfo = localtime(&rawtime); - strftime(buffer, 79, "%y-%m-%d", timeinfo); - date = buffer; + strftime(buffer, 79, "%Y-%m/%d", timeinfo); + + date = strprintf("%s/%s/%s", mBaseLogDir.c_str(), + mServerName.c_str(), buffer); + return date; } @@ -164,29 +173,20 @@ void ChatLogger::setServerName(const std::string &serverName) { DIR *dir = opendir((mLogDir + "/" + mServerName).c_str()); if (!dir) - makeDir(mLogDir + "/" + mServerName); + mkdir_r((mLogDir + "/" + mServerName).c_str()); else closedir(dir); } } -void ChatLogger::makeDir(const std::string &dir) -{ -#ifdef WIN32 - mkdir(dir.c_str()); -#else - mkdir(dir.c_str(), 0750); -#endif -} - void ChatLogger::loadLast(std::string name, std::list<std::string> &list, unsigned n) { std::ifstream logFile; + std::string fileName = strprintf("%s/%s.log", getDir().c_str(), + secureName(name).c_str()); - logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), - mServerName.c_str(), secureName(name).c_str(), - getDateString().c_str()).c_str(), std::ios::in); + logFile.open(fileName.c_str(), std::ios::in); if (!logFile.is_open()) return; diff --git a/src/chatlogger.h b/src/chatlogger.h index 6e096ac89..23d5d4a86 100644 --- a/src/chatlogger.h +++ b/src/chatlogger.h @@ -40,8 +40,6 @@ class ChatLogger */ ~ChatLogger(); - void setLogDir(const std::string &logDir); - /** * Enters a message in the log. The message will be timestamped. */ @@ -52,26 +50,30 @@ class ChatLogger void loadLast(std::string name, std::list<std::string> &list, unsigned n); - std::string getDateString() const; + std::string getDir() const; std::string secureName(std::string &str) const; void setServerName(const std::string &serverName); + void setBaseLogDir(const std::string &logDir) + { mBaseLogDir = logDir; } + private: /** * Sets the file to log to and opens it */ void setLogFile(const std::string &logFilename); - void writeTo(std::ofstream &file, const std::string &str) const; + void setLogDir(const std::string &logDir); - void makeDir(const std::string &dir); + void writeTo(std::ofstream &file, const std::string &str) const; std::ofstream mLogFile; std::string mLogDir; + std::string mBaseLogDir; std::string mServerName; - std::string mLogDate; + std::string mLogFileName; }; extern ChatLogger *chatLogger; diff --git a/src/client.cpp b/src/client.cpp index 8a6ec2116..7de58368c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -322,9 +322,9 @@ Client::Client(const Options &options): chatLogger = new ChatLogger; if (mOptions.chatLogDir == "") - chatLogger->setLogDir(mLocalDataDir + std::string("/logs/")); + chatLogger->setBaseLogDir(mLocalDataDir + std::string("/logs/")); else - chatLogger->setLogDir(mOptions.chatLogDir); + chatLogger->setBaseLogDir(mOptions.chatLogDir); logger->setLogToStandardOut(config.getBoolValue("logToStandardOut")); diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index 5fa0df29b..8373cb1c4 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -225,6 +225,7 @@ void PartyHandler::processPartySettings(Net::MessageIn &msg) return; Ea::partyTab = new PartyTab(); + Ea::partyTab->loadFromLogFile("#Party"); } // These seem to indicate the sharing mode for exp and items |