diff --git a/app.go b/app.go index c2005f1..6cff05f 100644 --- a/app.go +++ b/app.go @@ -23,6 +23,9 @@ type App interface { GetNowSeconds() int64 GetNowMillis() int64 GetNowNano() int64 + GetTimeOffset() int32 + SetTimeOffset(int32) + GetLocation() *time.Location RegisterMainThreadCb(func()) } @@ -50,6 +53,8 @@ type app struct { chGoLoopWait chan int64 nowTime time.Time nowUnixNano int64 + timeOffset int32 + location *time.Location imMsgHandlers [1024]func(q5.Args) maxRunDelay int64 maxScheduleTime int64 @@ -60,6 +65,7 @@ type app struct { func (this *app) init(userApp UserApp) { this.userApp = userApp this.nowTime = time.Now() + this.SetTimeOffset(0) atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano()) _timer = new(timer) _timer.init() @@ -223,6 +229,22 @@ func (this *app) GetNowNano() int64 { return this.nowUnixNano } +func (this *app) GetTimeOffset() int32 { + return this.timeOffset +} + +func (this *app) SetTimeOffset(offset int32) { + this.timeOffset = offset + this.location = time.FixedZone("UTC-f5", int(offset)) + if this.location == nil { + panic("SetTimeOffset error") + } +} + +func (this *app) GetLocation() *time.Location { + return this.location +} + func (this *app) outputRuningLog() { } diff --git a/syslog.go b/syslog.go index 9d5b8fd..a9ed9ea 100644 --- a/syslog.go +++ b/syslog.go @@ -98,7 +98,7 @@ func (this *sysLog) addLog(category int32, prefixStr string, format string, args ...interface{}) { p := &logMsgNode{} p.category = category - p.logMsg = time.Now().Format("2006-01-02 15:04:05") + + p.logMsg = q5.FormatUnixDateTime(_app.GetNowSeconds(), _app.GetLocation()) + prefixStr + " " + fmt.Sprintf(format, args...) + "\n" if category == LOG_INFO { @@ -130,7 +130,9 @@ func (this *sysLog) goSaveToFile() { this.msgMutex.Unlock() if workNode != nil { logDir := fmt.Sprintf(SYS_LOG_ROOT, GetApp().GetPkgName()) - fileName := fmt.Sprintf(TGLOG_FILENAME, os.Getpid(), time.Now().Format("20060102")) + fileName := fmt.Sprintf(TGLOG_FILENAME, + os.Getpid(), + q5.FormatUnixDateEx(_app.GetNowSeconds(), _app.GetLocation())) q5.ForceCreateDir(logDir) if f, err := os.OpenFile(logDir+fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666); err == nil { for workNode != nil { diff --git a/tglog.go b/tglog.go index cbef632..3fc15a4 100644 --- a/tglog.go +++ b/tglog.go @@ -62,7 +62,7 @@ func (this *tgLog) AddTrackLogEx( } { AccountId: accountId, Type: "track", - Time: time.Now().Format("2006-01-02 15:04:05"), + Time: q5.FormatUnixDateTime(_app.GetNowSeconds(), _app.GetLocation()), EventName: eventName, Ip: remoteAddr, Properties: prop, @@ -108,7 +108,9 @@ func (this *tgLog) goSaveToFile() { } func (this *tgLog) getLogFile(gameId int32) *os.File { - fileName := fmt.Sprintf(TGLOG_FILENAME, os.Getpid(), time.Now().Format("20060102")) + fileName := fmt.Sprintf(TGLOG_FILENAME, + os.Getpid(), + q5.FormatUnixDateEx(_app.GetNowSeconds(), _app.GetLocation())) logDir := "" if this.isPolyLog { logDir = fmt.Sprintf(POLY_TGLOG_ROOT, _app.GetPkgName(), gameId)