mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
log: Add -timestamp option
Allows users to define a new timestamp as formatted by strftime through CUtils::FormatTime Additionally -sanitize is no longer necessarily the first argument, but -timestamp and the actual timestamp must be last as it can contain spaces.
This commit is contained in:
@@ -106,6 +106,7 @@ public:
|
||||
|
||||
private:
|
||||
CString m_sLogPath;
|
||||
CString m_sTimestamp;
|
||||
bool m_bSanitize;
|
||||
vector<CLogRule> m_vRules;
|
||||
};
|
||||
@@ -268,15 +269,35 @@ CString CLogMod::GetServer()
|
||||
|
||||
bool CLogMod::OnLoad(const CString& sArgs, CString& sMessage)
|
||||
{
|
||||
size_t uIndex = 0;
|
||||
if (sArgs.Token(0).Equals("-sanitize"))
|
||||
{
|
||||
m_bSanitize = true;
|
||||
++uIndex;
|
||||
VCString vsArgs;
|
||||
sArgs.Split(" ", vsArgs);
|
||||
|
||||
bool bHaveTimestamp = false;
|
||||
bool bHaveLogPath = false;
|
||||
for (CString& sArg : vsArgs) {
|
||||
if (sArg.Equals("-sanitize")) {
|
||||
m_bSanitize = true;
|
||||
} else if (sArg.Equals("-timestamp")) {
|
||||
// Everything after this must be timestamp
|
||||
bHaveTimestamp = true;
|
||||
} else {
|
||||
if (bHaveTimestamp) {
|
||||
m_sTimestamp += sArg + " ";
|
||||
} else {
|
||||
// Only one arg may be LogPath
|
||||
if (bHaveLogPath) {
|
||||
sMessage = "Invalid args [" + sArgs + "]. Only one log path allowed. Check that there are no spaces in the path.";
|
||||
return false;
|
||||
}
|
||||
m_sLogPath = sArg;
|
||||
bHaveLogPath = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use load parameter as save path
|
||||
m_sLogPath = sArgs.Token(uIndex);
|
||||
if (m_sTimestamp.empty()) {
|
||||
m_sTimestamp = "[%H:%M:%S] ";
|
||||
}
|
||||
|
||||
// Add default filename to path if it's a folder
|
||||
if (GetType() == CModInfo::UserModule) {
|
||||
@@ -313,7 +334,7 @@ bool CLogMod::OnLoad(const CString& sArgs, CString& sMessage)
|
||||
sMessage = "Invalid log path ["+m_sLogPath+"].";
|
||||
return false;
|
||||
} else {
|
||||
sMessage = "Logging to ["+m_sLogPath+"].";
|
||||
sMessage = "Logging to ["+m_sLogPath+"]. Using timestamp ["+m_sTimestamp+"]";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user