Permalink
Browse files

Add -sanitize option to log module.

  • Loading branch information...
1 parent 10a982b commit 3ba4598994a12303fcf099db665b3f6cbc1fe636 @ravomavain ravomavain committed May 11, 2013
Showing with 15 additions and 4 deletions.
  1. +15 −4 modules/log.cpp
View
19 modules/log.cpp
@@ -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 @@ class CLogMod: public CModule {
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");
}

0 comments on commit 3ba4598

Please sign in to comment.