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:
NuclearW
2014-09-30 14:33:42 -04:00
committed by Andreas Lutro
parent a314d3057e
commit 5ca8cb51ba

View File

@@ -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;
}
}