Add clang-format configuration.

For now, it uses tabs like before, to make the diff easier to read/check.
One of following commits will switch it to spaces.
This commit is contained in:
Alexey Sokolov
2015-12-06 22:36:35 +00:00
parent 02f8749a8b
commit 33b0627d75
132 changed files with 12743 additions and 8904 deletions
+53 -37
View File
@@ -23,11 +23,15 @@
#include <time.h>
class CAdminLogMod : public CModule {
public:
public:
MODCONSTRUCTOR(CAdminLogMod) {
AddHelpCommand();
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(&CAdminLogMod::OnShowCommand), "", "Show the logging target");
AddCommand("Target", static_cast<CModCommand::ModCmdFunc>(&CAdminLogMod::OnTargetCommand), "<file|syslog|both> [path]", "Set the logging target");
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(
&CAdminLogMod::OnShowCommand),
"", "Show the logging target");
AddCommand("Target", static_cast<CModCommand::ModCmdFunc>(
&CAdminLogMod::OnTargetCommand),
"<file|syslog|both> [path]", "Set the logging target");
openlog("znc", LOG_PID, LOG_DAEMON);
}
@@ -36,7 +40,7 @@ public:
closelog();
}
bool OnLoad(const CString & sArgs, CString & sMessage) override {
bool OnLoad(const CString& sArgs, CString& sMessage) override {
CString sTarget = GetNV("target");
if (sTarget.Equals("syslog"))
m_eLogMode = LOG_TO_SYSLOG;
@@ -49,41 +53,52 @@ public:
SetLogFilePath(GetNV("path"));
Log("Logging started. ZNC PID[" + CString(getpid()) + "] UID/GID[" + CString(getuid()) + ":" + CString(getgid()) + "]");
Log("Logging started. ZNC PID[" + CString(getpid()) + "] UID/GID[" +
CString(getuid()) + ":" + CString(getgid()) + "]");
return true;
}
void OnIRCConnected() override {
Log("[" + GetUser()->GetUserName() + "/" + GetNetwork()->GetName() + "] connected to IRC: " + GetNetwork()->GetCurrentServer()->GetName());
Log("[" + GetUser()->GetUserName() + "/" + GetNetwork()->GetName() +
"] connected to IRC: " +
GetNetwork()->GetCurrentServer()->GetName());
}
void OnIRCDisconnected() override {
Log("[" + GetUser()->GetUserName() + "/" + GetNetwork()->GetName() + "] disconnected from IRC");
Log("[" + GetUser()->GetUserName() + "/" + GetNetwork()->GetName() +
"] disconnected from IRC");
}
EModRet OnRaw(CString& sLine) override {
if (sLine.StartsWith("ERROR ")) {
//ERROR :Closing Link: nick[24.24.24.24] (Excess Flood)
//ERROR :Closing Link: nick[24.24.24.24] Killer (Local kill by Killer (reason))
// ERROR :Closing Link: nick[24.24.24.24] (Excess Flood)
// ERROR :Closing Link: nick[24.24.24.24] Killer (Local kill by
// Killer (reason))
CString sError(sLine.substr(6));
if (sError.Left(1) == ":")
sError.LeftChomp();
Log("[" + GetUser()->GetUserName() + "/" + GetNetwork()->GetName() + "] disconnected from IRC: " +
GetNetwork()->GetCurrentServer()->GetName() + " [" + sError + "]", LOG_NOTICE);
if (sError.Left(1) == ":") sError.LeftChomp();
Log("[" + GetUser()->GetUserName() + "/" + GetNetwork()->GetName() +
"] disconnected from IRC: " +
GetNetwork()->GetCurrentServer()->GetName() + " [" +
sError + "]",
LOG_NOTICE);
}
return CONTINUE;
}
}
void OnClientLogin() override {
Log("[" + GetUser()->GetUserName() + "] connected to ZNC from " + GetClient()->GetRemoteIP());
Log("[" + GetUser()->GetUserName() + "] connected to ZNC from " +
GetClient()->GetRemoteIP());
}
void OnClientDisconnect() override {
Log("[" + GetUser()->GetUserName() + "] disconnected from ZNC from " + GetClient()->GetRemoteIP());
Log("[" + GetUser()->GetUserName() + "] disconnected from ZNC from " +
GetClient()->GetRemoteIP());
}
void OnFailedLogin(const CString& sUsername, const CString& sRemoteIP) override {
Log("[" + sUsername + "] failed to login from " + sRemoteIP, LOG_WARNING);
void OnFailedLogin(const CString& sUsername,
const CString& sRemoteIP) override {
Log("[" + sUsername + "] failed to login from " + sRemoteIP,
LOG_WARNING);
}
void SetLogFilePath(CString sPath) {
@@ -104,8 +119,7 @@ public:
}
void Log(CString sLine, int iPrio = LOG_INFO) {
if (m_eLogMode & LOG_TO_SYSLOG)
syslog(iPrio, "%s", sLine.c_str());
if (m_eLogMode & LOG_TO_SYSLOG) syslog(iPrio, "%s", sLine.c_str());
if (m_eLogMode & LOG_TO_FILE) {
time_t curtime;
@@ -114,14 +128,15 @@ public:
time(&curtime);
timeinfo = localtime(&curtime);
strftime(buf,sizeof(buf),"[%Y-%m-%d %H:%M:%S] ",timeinfo);
strftime(buf, sizeof(buf), "[%Y-%m-%d %H:%M:%S] ", timeinfo);
CFile LogFile(m_sLogFile);
if (LogFile.Open(O_WRONLY | O_APPEND | O_CREAT))
LogFile.Write(buf + sLine + "\n");
else
DEBUG("Failed to write to [" << m_sLogFile << "]: " << strerror(errno));
DEBUG("Failed to write to [" << m_sLogFile
<< "]: " << strerror(errno));
}
}
@@ -175,34 +190,35 @@ public:
void OnShowCommand(const CString& sCommand) {
CString sTarget;
switch (m_eLogMode)
{
case LOG_TO_FILE:
sTarget = "file";
break;
case LOG_TO_SYSLOG:
sTarget = "syslog";
break;
case LOG_TO_BOTH:
sTarget = "both, file and syslog";
break;
switch (m_eLogMode) {
case LOG_TO_FILE:
sTarget = "file";
break;
case LOG_TO_SYSLOG:
sTarget = "syslog";
break;
case LOG_TO_BOTH:
sTarget = "both, file and syslog";
break;
}
PutModule("Logging is enabled for " + sTarget);
if (m_eLogMode != LOG_TO_SYSLOG)
PutModule("Log file will be written to [" + m_sLogFile + "]");
}
private:
private:
enum LogMode {
LOG_TO_FILE = 1 << 0,
LOG_TO_FILE = 1 << 0,
LOG_TO_SYSLOG = 1 << 1,
LOG_TO_BOTH = LOG_TO_FILE | LOG_TO_SYSLOG
LOG_TO_BOTH = LOG_TO_FILE | LOG_TO_SYSLOG
};
LogMode m_eLogMode = LOG_TO_FILE;
CString m_sLogFile;
};
template<> void TModInfo<CAdminLogMod>(CModInfo& Info) {
template <>
void TModInfo<CAdminLogMod>(CModInfo& Info) {
Info.SetWikiPage("adminlog");
}