This commit is contained in:
aozhiwei 2023-09-09 10:50:58 +08:00
parent 72619df2c1
commit 35c7b10247
3 changed files with 30 additions and 4 deletions

22
app.go
View File

@ -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() {
}

View File

@ -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 {

View File

@ -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)