我想在本地时间输出America/Los_Angeles
到日志文件。目前,我正在使用 UTC 时间。我希望这三个功能中存在解决方案。
/* src/lib/timing.c line 196 */
char* xdebug_nanotime_to_chars(uint64_t nanotime, unsigned char precision)
{
char *res;
time_t secs;
secs = (time_t)(nanotime / NANOS_IN_SEC);
if (precision > 0) {
res = xdmalloc(30);
} else {
res = xdmalloc(20);
}
strftime(res, 20, "%Y-%m-%d %H:%M:%S", gmtime(&secs));
if (precision > 0) {
sprintf(res + 19, ".%09u", (uint32_t)(nanotime % NANOS_IN_SEC));
if (precision < 9) {
*(res + 20 + precision) = '\0';
}
}
return res;
}
打开日志。设置log_open_timestring
功能xdebug_nanotime_to_chars
。
/* src/lib/log.c line 586 */
void xdebug_open_log(void)
{
/* initialize remote log file */
XG_LIB(log_file) = NULL;
XG_LIB(log_opened_message_sent) = 0;
XG_LIB(log_open_timestring) = NULL;
if (XINI_LIB(log) && strlen(XINI_LIB(log))) {
XG_LIB(log_file) = xdebug_fopen(XINI_LIB(log), "a", NULL, NULL);
}
if (XG_LIB(log_file)) {
XG_LIB(log_open_timestring) = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6);
} else if (strlen(XINI_LIB(log))) {
xdebug_log_diagnose_permissions(XLOG_CHAN_LOGFILE, NULL, XINI_LIB(log));
}
}
将日志打开时间打印到日志文件:
/* src/lib/log.c line 56 */
static inline void xdebug_internal_log(int channel, int log_level, const char *message)
{
zend_ulong pid;
if (!XG_LIB(log_file)) {
return;
}
pid = xdebug_get_pid();
if (!XG_LIB(log_opened_message_sent) && XG_LIB(log_open_timestring)) {
XG_LIB(log_opened_message_sent) = 1;
fprintf(XG_LIB(log_file), "[" ZEND_ULONG_FMT "] Log opened at %s\n", pid, XG_LIB(log_open_timestring));
fflush(XG_LIB(log_file));
xdfree(XG_LIB(log_open_timestring));
XG_LIB(log_open_timestring) = NULL;
}
fprintf(
XG_LIB(log_file),
"[" ZEND_ULONG_FMT "] %s%s%s\n",
pid,
xdebug_channel_name[channel],
xdebug_log_prefix[log_level],
message
);
fflush(XG_LIB(log_file));
}