Add -sanitize option to log module.

This commit is contained in:
Ravomavain
2013-05-11 21:38:02 +02:00
parent 10a982b6d3
commit 3ba4598994
+15 -4
View File
@@ -17,7 +17,10 @@ using std::vector;
class CLogMod: public CModule {
public:
MODCONSTRUCTOR(CLogMod) {}
MODCONSTRUCTOR(CLogMod)
{
m_bSanitize = false;
}
void PutLog(const CString& sLine, const CString& sWindow = "status");
void PutLog(const CString& sLine, const CChan& Channel);
@@ -54,6 +57,7 @@ public:
private:
CString m_sLogPath;
bool m_bSanitize;
};
void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/)
@@ -88,7 +92,7 @@ void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/
if (!CFile::Exists(sLogDir)) CDir::MakeDir(sLogDir);
if (LogFile.Open(O_WRONLY | O_APPEND | O_CREAT))
{
LogFile.Write(CUtils::FormatTime(curtime, "[%H:%M:%S] ", m_pUser->GetTimezone()) + sLine + "\n");
LogFile.Write(CUtils::FormatTime(curtime, "[%H:%M:%S] ", m_pUser->GetTimezone()) + (m_bSanitize ? sLine.StripControls_n() : sLine) + "\n");
} else
DEBUG("Could not open log file [" << sPath << "]: " << strerror(errno));
}
@@ -118,8 +122,15 @@ 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;
}
// Use load parameter as save path
m_sLogPath = sArgs;
m_sLogPath = sArgs.Token(uIndex);
// Add default filename to path if it's a folder
if (GetType() == CModInfo::UserModule) {
@@ -282,7 +293,7 @@ template<> void TModInfo<CLogMod>(CModInfo& Info) {
Info.AddType(CModInfo::NetworkModule);
Info.AddType(CModInfo::GlobalModule);
Info.SetHasArgs(true);
Info.SetArgsHelpText("Optional path where to store logs.");
Info.SetArgsHelpText("[-sanitize] Optional path where to store logs.");
Info.SetWikiPage("log");
}