Move TZ-related code to own place.

This commit is contained in:
Alexey Sokolov
2012-03-22 22:20:41 +07:00
parent eca0211bb8
commit 355d5feb7a
6 changed files with 68 additions and 50 deletions

View File

@@ -58,21 +58,15 @@ void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/
{
CString sPath;
time_t curtime;
tm* timeinfo;
char buffer[1024];
time(&curtime);
// Don't forget the user's timezone offset
setenv("TZ", m_pUser->GetTimezone().c_str(), 1);
timeinfo = localtime(&curtime);
// Generate file name
if (!strftime(buffer, sizeof(buffer), m_sLogPath.c_str(), timeinfo))
sPath = CUtils::FormatTime(curtime, m_sLogPath, m_pUser->GetTimezone());
if (sPath.empty())
{
DEBUG("Could not format log path [" << sPath << "]");
return;
}
sPath = buffer;
// $WINDOW has to be handled last, since it can contain %
sPath.Replace("$NETWORK", (m_pNetwork ? m_pNetwork->GetName() : "znc"));
@@ -92,10 +86,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))
{
snprintf(buffer, sizeof(buffer), "[%02d:%02d:%02d] ",
timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
LogFile.Write(buffer + sLine + "\n");
LogFile.Write(CUtils::FormatTime(curtime, "[%H:%M:%S] ", m_pUser->GetTimezone()) + sLine + "\n");
} else
DEBUG("Could not open log file [" << sPath << "]: " << strerror(errno));
}