Go initializes the log file and clears the contents

 Go initializes the log file and clears the contents

func init() {
	fileName := "test.log"
	logFile, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0766)
	if err != nil {
		panic(err)
	}
	logFile.Truncate(0)
	log.SetOutput(logFile)
	log.SetPrefix("[MyTest]")
	log.SetFlags(log.LstdFlags | log.Lshortfile | log.LUTC)
}

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example