mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
committed by
Alexey Sokolov
parent
f63c3131eb
commit
3a3155f9d5
@@ -27,7 +27,7 @@ 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>", "Set 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);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
else
|
||||
m_eLogMode = LOG_TO_FILE;
|
||||
|
||||
m_sLogFile = GetSavePath() + "/znc.log";
|
||||
SetLogFilePath(GetNV("path"));
|
||||
|
||||
Log("Logging started. ZNC PID[" + CString(getpid()) + "] UID/GID[" + CString(getuid()) + ":" + CString(getgid()) + "]");
|
||||
return true;
|
||||
@@ -86,6 +86,23 @@ public:
|
||||
Log("[" + sUsername + "] failed to login from " + sRemoteIP, LOG_WARNING);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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());
|
||||
@@ -117,14 +134,14 @@ public:
|
||||
}
|
||||
|
||||
void OnTargetCommand(const CString& sCommand) {
|
||||
CString sArg = sCommand.Token(1, true);
|
||||
CString sArg = sCommand.Token(1, false);
|
||||
CString sTarget;
|
||||
CString sMessage;
|
||||
LogMode mode;
|
||||
|
||||
if (sArg.Equals("file")) {
|
||||
sTarget = "file";
|
||||
sMessage = "Now only logging to file";
|
||||
sMessage = "Now logging to file";
|
||||
mode = LOG_TO_FILE;
|
||||
} else if (sArg.Equals("syslog")) {
|
||||
sTarget = "syslog";
|
||||
@@ -132,17 +149,23 @@ public:
|
||||
mode = LOG_TO_SYSLOG;
|
||||
} else if (sArg.Equals("both")) {
|
||||
sTarget = "both";
|
||||
sMessage = "Now logging to file and syslog";
|
||||
sMessage = "Now logging to syslog and file";
|
||||
mode = LOG_TO_BOTH;
|
||||
} else {
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: Target <file|syslog|both>");
|
||||
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 + "]";
|
||||
}
|
||||
|
||||
Log(sMessage);
|
||||
SetNV("target", sTarget);
|
||||
m_eLogMode = mode;
|
||||
|
||||
Reference in New Issue
Block a user