Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogFile::getLogFileName 时间规则需要参照g_logTimeZone, #493

Open
mosxuqian opened this issue Dec 3, 2020 · 0 comments
Open

LogFile::getLogFileName 时间规则需要参照g_logTimeZone, #493

mosxuqian opened this issue Dec 3, 2020 · 0 comments

Comments

@mosxuqian
Copy link

参照Logger::Impl::formatTime来处理,更加合理,并且能够让log文件内容的时间和log文件名保持一致性。

新的代码,如下:
string LogFile::getLogFileName(const string& basename, time_t* now)
{
string filename;
filename.reserve(basename.size() + 64);
filename = basename;
char timebuf[32];
struct tm tm;
*now = time(NULL);
if (g_logTimeZone.valid())
{
tm = g_logTimeZone.toLocalTime(now);
}
else
{
::gmtime_r(&now, &tm); // FIXME TimeZone::fromUtcTime
}
strftime(timebuf, sizeof timebuf, ".%Y%m%d-%H%M%S.", &tm);
filename += timebuf;

filename += ProcessInfo::hostname();

char pidbuf[32];
snprintf(pidbuf, sizeof pidbuf, ".%d", ProcessInfo::pid());
filename += pidbuf;

filename += ".log";

return filename;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant