natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.8k stars 591 forks source link

UTC time #42

Closed mkulkarni15 closed 7 years ago

mkulkarni15 commented 7 years ago

I have tried setting LocalTime false, true and not using the parameter. Neither of which is resulting in UTC time prepended to the log. Is there something obvious i am missing?

package main

import ( "log" "gopkg.in/natefinch/lumberjack.v2" "time" "fmt" ) func main() {

log.SetOutput(&lumberjack.Logger{ Filename: "sed.log", MaxSize: 50, // megabytes MaxAge: 28, //days LocalTime: false, }) localTime := time.Now() utcTime := localTime.UTC()

// Display the results
fmt.Printf("Local Time: %v\n", localTime)
fmt.Printf("UTC Time: %v\n", utcTime)

log.Println("DEBUG %s", localTime)
log.Println("DEBUG %s", utcTime)

}

go run lumber.go Local Time: 2017-05-09 12:13:26.205047356 -0700 PDT UTC Time: 2017-05-09 19:13:26.205047356 +0000 UTC

cat sed.log

2017/05/09 12:13:26 DEBUG %s 2017-05-09 12:13:26.205047356 -0700 PDT 2017/05/09 12:13:26 DEBUG %s 2017-05-09 19:13:26.205047356 +0000 UTC

mkulkarni15 commented 7 years ago

log.SetFlags(log.LstdFlags | log.LUTC) helped me.

natefinch commented 7 years ago

So, yeah, Localtime on Lumberjack just controls the timestamp appended to rolled log files. What gets output inside the logs is completely beyond the control of Lumberjack. It just writes what you tell it to write.