mirror of
https://github.com/znc/znc.git
synced 2026-08-09 18:32:55 +02:00
clang-format: switch tabs to spaces
I like tabs, but I have to admit that spaces make source code more consistent, because every editor/viewer tends to render tabs differently :(
This commit is contained in:
+164
-164
@@ -24,202 +24,202 @@
|
||||
|
||||
class CAdminLogMod : public CModule {
|
||||
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");
|
||||
openlog("znc", LOG_PID, LOG_DAEMON);
|
||||
}
|
||||
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");
|
||||
openlog("znc", LOG_PID, LOG_DAEMON);
|
||||
}
|
||||
|
||||
virtual ~CAdminLogMod() {
|
||||
Log("Logging ended.");
|
||||
closelog();
|
||||
}
|
||||
virtual ~CAdminLogMod() {
|
||||
Log("Logging ended.");
|
||||
closelog();
|
||||
}
|
||||
|
||||
bool OnLoad(const CString& sArgs, CString& sMessage) override {
|
||||
CString sTarget = GetNV("target");
|
||||
if (sTarget.Equals("syslog"))
|
||||
m_eLogMode = LOG_TO_SYSLOG;
|
||||
else if (sTarget.Equals("both"))
|
||||
m_eLogMode = LOG_TO_BOTH;
|
||||
else if (sTarget.Equals("file"))
|
||||
m_eLogMode = LOG_TO_FILE;
|
||||
else
|
||||
m_eLogMode = LOG_TO_FILE;
|
||||
bool OnLoad(const CString& sArgs, CString& sMessage) override {
|
||||
CString sTarget = GetNV("target");
|
||||
if (sTarget.Equals("syslog"))
|
||||
m_eLogMode = LOG_TO_SYSLOG;
|
||||
else if (sTarget.Equals("both"))
|
||||
m_eLogMode = LOG_TO_BOTH;
|
||||
else if (sTarget.Equals("file"))
|
||||
m_eLogMode = LOG_TO_FILE;
|
||||
else
|
||||
m_eLogMode = LOG_TO_FILE;
|
||||
|
||||
SetLogFilePath(GetNV("path"));
|
||||
SetLogFilePath(GetNV("path"));
|
||||
|
||||
Log("Logging started. ZNC PID[" + CString(getpid()) + "] UID/GID[" +
|
||||
CString(getuid()) + ":" + CString(getgid()) + "]");
|
||||
return true;
|
||||
}
|
||||
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());
|
||||
}
|
||||
void OnIRCConnected() override {
|
||||
Log("[" + GetUser()->GetUserName() + "/" + GetNetwork()->GetName() +
|
||||
"] connected to IRC: " +
|
||||
GetNetwork()->GetCurrentServer()->GetName());
|
||||
}
|
||||
|
||||
void OnIRCDisconnected() override {
|
||||
Log("[" + GetUser()->GetUserName() + "/" + GetNetwork()->GetName() +
|
||||
"] disconnected from IRC");
|
||||
}
|
||||
void OnIRCDisconnected() override {
|
||||
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))
|
||||
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);
|
||||
}
|
||||
return CONTINUE;
|
||||
}
|
||||
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))
|
||||
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);
|
||||
}
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
void OnClientLogin() override {
|
||||
Log("[" + GetUser()->GetUserName() + "] connected to ZNC from " +
|
||||
GetClient()->GetRemoteIP());
|
||||
}
|
||||
void OnClientLogin() override {
|
||||
Log("[" + GetUser()->GetUserName() + "] connected to ZNC from " +
|
||||
GetClient()->GetRemoteIP());
|
||||
}
|
||||
|
||||
void OnClientDisconnect() override {
|
||||
Log("[" + GetUser()->GetUserName() + "] disconnected from ZNC from " +
|
||||
GetClient()->GetRemoteIP());
|
||||
}
|
||||
void OnClientDisconnect() override {
|
||||
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) {
|
||||
if (sPath.empty()) {
|
||||
sPath = GetSavePath() + "/znc.log";
|
||||
}
|
||||
void SetLogFilePath(CString sPath) {
|
||||
if (sPath.empty()) {
|
||||
sPath = GetSavePath() + "/znc.log";
|
||||
}
|
||||
|
||||
CFile LogFile(sPath);
|
||||
CString sLogDir = LogFile.GetDir();
|
||||
struct stat ModDirInfo;
|
||||
CFile::GetInfo(GetSavePath(), ModDirInfo);
|
||||
if (!CFile::Exists(sLogDir)) {
|
||||
CDir::MakeDir(sLogDir, ModDirInfo.st_mode);
|
||||
}
|
||||
CFile LogFile(sPath);
|
||||
CString sLogDir = LogFile.GetDir();
|
||||
struct stat ModDirInfo;
|
||||
CFile::GetInfo(GetSavePath(), ModDirInfo);
|
||||
if (!CFile::Exists(sLogDir)) {
|
||||
CDir::MakeDir(sLogDir, ModDirInfo.st_mode);
|
||||
}
|
||||
|
||||
m_sLogFile = sPath;
|
||||
SetNV("path", sPath);
|
||||
}
|
||||
m_sLogFile = sPath;
|
||||
SetNV("path", sPath);
|
||||
}
|
||||
|
||||
void Log(CString sLine, int iPrio = LOG_INFO) {
|
||||
if (m_eLogMode & LOG_TO_SYSLOG) syslog(iPrio, "%s", sLine.c_str());
|
||||
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_FILE) {
|
||||
time_t curtime;
|
||||
tm* timeinfo;
|
||||
char buf[23];
|
||||
if (m_eLogMode & LOG_TO_FILE) {
|
||||
time_t curtime;
|
||||
tm* timeinfo;
|
||||
char buf[23];
|
||||
|
||||
time(&curtime);
|
||||
timeinfo = localtime(&curtime);
|
||||
strftime(buf, sizeof(buf), "[%Y-%m-%d %H:%M:%S] ", timeinfo);
|
||||
time(&curtime);
|
||||
timeinfo = localtime(&curtime);
|
||||
strftime(buf, sizeof(buf), "[%Y-%m-%d %H:%M:%S] ", timeinfo);
|
||||
|
||||
CFile LogFile(m_sLogFile);
|
||||
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));
|
||||
}
|
||||
}
|
||||
if (LogFile.Open(O_WRONLY | O_APPEND | O_CREAT))
|
||||
LogFile.Write(buf + sLine + "\n");
|
||||
else
|
||||
DEBUG("Failed to write to [" << m_sLogFile
|
||||
<< "]: " << strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
void OnModCommand(const CString& sCommand) override {
|
||||
if (!GetUser()->IsAdmin()) {
|
||||
PutModule("Access denied");
|
||||
} else {
|
||||
HandleCommand(sCommand);
|
||||
}
|
||||
}
|
||||
void OnModCommand(const CString& sCommand) override {
|
||||
if (!GetUser()->IsAdmin()) {
|
||||
PutModule("Access denied");
|
||||
} else {
|
||||
HandleCommand(sCommand);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTargetCommand(const CString& sCommand) {
|
||||
CString sArg = sCommand.Token(1, false);
|
||||
CString sTarget;
|
||||
CString sMessage;
|
||||
LogMode mode;
|
||||
void OnTargetCommand(const CString& sCommand) {
|
||||
CString sArg = sCommand.Token(1, false);
|
||||
CString sTarget;
|
||||
CString sMessage;
|
||||
LogMode mode;
|
||||
|
||||
if (sArg.Equals("file")) {
|
||||
sTarget = "file";
|
||||
sMessage = "Now logging to file";
|
||||
mode = LOG_TO_FILE;
|
||||
} else if (sArg.Equals("syslog")) {
|
||||
sTarget = "syslog";
|
||||
sMessage = "Now only logging to syslog";
|
||||
mode = LOG_TO_SYSLOG;
|
||||
} else if (sArg.Equals("both")) {
|
||||
sTarget = "both";
|
||||
sMessage = "Now logging to syslog and file";
|
||||
mode = LOG_TO_BOTH;
|
||||
} else {
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: Target <file|syslog|both> [path]");
|
||||
} else {
|
||||
PutModule("Unknown target");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (sArg.Equals("file")) {
|
||||
sTarget = "file";
|
||||
sMessage = "Now logging to file";
|
||||
mode = LOG_TO_FILE;
|
||||
} else if (sArg.Equals("syslog")) {
|
||||
sTarget = "syslog";
|
||||
sMessage = "Now only logging to syslog";
|
||||
mode = LOG_TO_SYSLOG;
|
||||
} else if (sArg.Equals("both")) {
|
||||
sTarget = "both";
|
||||
sMessage = "Now logging to syslog and file";
|
||||
mode = LOG_TO_BOTH;
|
||||
} else {
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: Target <file|syslog|both> [path]");
|
||||
} else {
|
||||
PutModule("Unknown target");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode != LOG_TO_SYSLOG) {
|
||||
CString sPath = sCommand.Token(2, true);
|
||||
SetLogFilePath(sPath);
|
||||
sMessage += " [" + sPath + "]";
|
||||
}
|
||||
if (mode != LOG_TO_SYSLOG) {
|
||||
CString sPath = sCommand.Token(2, true);
|
||||
SetLogFilePath(sPath);
|
||||
sMessage += " [" + sPath + "]";
|
||||
}
|
||||
|
||||
Log(sMessage);
|
||||
SetNV("target", sTarget);
|
||||
m_eLogMode = mode;
|
||||
PutModule(sMessage);
|
||||
}
|
||||
Log(sMessage);
|
||||
SetNV("target", sTarget);
|
||||
m_eLogMode = mode;
|
||||
PutModule(sMessage);
|
||||
}
|
||||
|
||||
void OnShowCommand(const CString& sCommand) {
|
||||
CString sTarget;
|
||||
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 + "]");
|
||||
}
|
||||
PutModule("Logging is enabled for " + sTarget);
|
||||
if (m_eLogMode != LOG_TO_SYSLOG)
|
||||
PutModule("Log file will be written to [" + m_sLogFile + "]");
|
||||
}
|
||||
|
||||
private:
|
||||
enum LogMode {
|
||||
LOG_TO_FILE = 1 << 0,
|
||||
LOG_TO_SYSLOG = 1 << 1,
|
||||
LOG_TO_BOTH = LOG_TO_FILE | LOG_TO_SYSLOG
|
||||
};
|
||||
LogMode m_eLogMode = LOG_TO_FILE;
|
||||
CString m_sLogFile;
|
||||
enum LogMode {
|
||||
LOG_TO_FILE = 1 << 0,
|
||||
LOG_TO_SYSLOG = 1 << 1,
|
||||
LOG_TO_BOTH = LOG_TO_FILE | LOG_TO_SYSLOG
|
||||
};
|
||||
LogMode m_eLogMode = LOG_TO_FILE;
|
||||
CString m_sLogFile;
|
||||
};
|
||||
|
||||
template <>
|
||||
void TModInfo<CAdminLogMod>(CModInfo& Info) {
|
||||
Info.SetWikiPage("adminlog");
|
||||
Info.SetWikiPage("adminlog");
|
||||
}
|
||||
|
||||
GLOBALMODULEDEFS(CAdminLogMod, "Log ZNC events to file and/or syslog.")
|
||||
|
||||
Reference in New Issue
Block a user