summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-11-18 19:12:49 +0300
committerAndrei Karas <akaras@inbox.ru>2015-11-18 19:12:49 +0300
commitfc84c591bff151bbe1b18af144ad55d49ff1028e (patch)
tree3b2a1a7a0e1d231048571018dba8c356611ee7ff /src
parentf1812857720449697c9106a7a3776b7202258cb3 (diff)
downloadplus-fc84c591bff151bbe1b18af144ad55d49ff1028e.tar.gz
plus-fc84c591bff151bbe1b18af144ad55d49ff1028e.tar.bz2
plus-fc84c591bff151bbe1b18af144ad55d49ff1028e.tar.xz
plus-fc84c591bff151bbe1b18af144ad55d49ff1028e.zip
Fix code style in chatlogger.
Diffstat (limited to 'src')
-rw-r--r--src/chatlogger.cpp46
-rw-r--r--src/chatlogger.h8
2 files changed, 35 insertions, 19 deletions
diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp
index 6ee03921f..5c40e1b56 100644
--- a/src/chatlogger.cpp
+++ b/src/chatlogger.cpp
@@ -60,12 +60,14 @@ void ChatLogger::setLogFile(const std::string &logFilename)
if (mLogFile.is_open())
mLogFile.close();
- mLogFile.open(logFilename.c_str(), std::ios_base::app);
+ mLogFile.open(logFilename.c_str(),
+ std::ios_base::app);
mLogFileName = logFilename;
if (!mLogFile.is_open())
{
- std::cout << "Warning: error while opening " << logFilename <<
+ std::cout << "Warning: error while opening " <<
+ logFilename <<
" for writing.\n";
}
}
@@ -89,7 +91,8 @@ void ChatLogger::log(std::string str)
const std::string &dateStr = getDir();
const std::string logFileName = strprintf(
"%s/#General.log", dateStr.c_str());
- if (!mLogFile.is_open() || logFileName != mLogFileName)
+ if (!mLogFile.is_open() ||
+ logFileName != mLogFileName)
{
setLogDir(dateStr);
setLogFile(logFileName);
@@ -99,7 +102,8 @@ void ChatLogger::log(std::string str)
writeTo(mLogFile, str);
}
-void ChatLogger::log(std::string name, std::string str)
+void ChatLogger::log(std::string name,
+ std::string str)
{
const std::string &dateStr = getDir();
const std::string logFileName = strprintf("%s/%s.log",
@@ -127,8 +131,10 @@ std::string ChatLogger::getDir() const
strftime(buffer, 79, "%Y-%m/%d", timeinfo);
- date = strprintf("%s/%s/%s", mBaseLogDir.c_str(),
- mServerName.c_str(), buffer);
+ date = strprintf("%s/%s/%s",
+ mBaseLogDir.c_str(),
+ mServerName.c_str(),
+ buffer);
return date;
}
@@ -139,13 +145,19 @@ std::string ChatLogger::secureName(std::string &name)
for (size_t f = 0; f < sz; f ++)
{
const unsigned char ch = name[f];
- if ((ch < '0' || ch > '9')
- && (ch < 'a' || ch > 'z')
- && (ch < 'A' || ch > 'Z')
- && ch != '-' && ch != '+' && ch != '='
- && ch != '.' && ch != ',' && ch != ')'
- && ch != '(' && ch != '[' && ch != ']'
- && ch != '#')
+ if ((ch < '0' || ch > '9') &&
+ (ch < 'a' || ch > 'z') &&
+ (ch < 'A' || ch > 'Z') &&
+ ch != '-' &&
+ ch != '+' &&
+ ch != '=' &&
+ ch != '.' &&
+ ch != ',' &&
+ ch != ')' &&
+ ch != '(' &&
+ ch != '[' &&
+ ch != ']' &&
+ ch != '#')
{
name[f] = '_';
}
@@ -181,11 +193,13 @@ void ChatLogger::setServerName(const std::string &serverName)
}
}
-void ChatLogger::loadLast(std::string name, std::list<std::string> &list,
- const unsigned n) const
+void ChatLogger::loadLast(std::string name,
+ std::list<std::string> &list,
+ const unsigned int n) const
{
std::ifstream logFile;
- std::string fileName = strprintf("%s/%s.log", getDir().c_str(),
+ std::string fileName = strprintf("%s/%s.log",
+ getDir().c_str(),
secureName(name).c_str());
logFile.open(fileName.c_str(), std::ios::in);
diff --git a/src/chatlogger.h b/src/chatlogger.h
index 421326e30..62ee4b2f7 100644
--- a/src/chatlogger.h
+++ b/src/chatlogger.h
@@ -50,8 +50,9 @@ class ChatLogger final
void log(std::string name, std::string str);
- void loadLast(std::string name, std::list<std::string> &list,
- const unsigned n) const;
+ void loadLast(std::string name,
+ std::list<std::string> &list,
+ const unsigned int n) const;
std::string getDir() const A_WARN_UNUSED;
@@ -72,7 +73,8 @@ class ChatLogger final
void setLogDir(const std::string &logDir);
- static void writeTo(std::ofstream &file, const std::string &str);
+ static void writeTo(std::ofstream &file,
+ const std::string &str);
std::ofstream mLogFile;
std::string mLogDir;