我试图为我的代码添加日志,但我无法在单独的行上获取每个日志
这是我的代码
package main
import (
"log"
"os"
)
func update(){
log.Println(1,"update")
log.Println(1,"update")
log.Println(1,"update")
log.Println(1,"update")
}
func install(){
log.Println(1,"install")
log.Println(1,"install")
log.Println(1,"install")
log.Println(1,"install")
}
func main() {
// make sure log.txt exists first
// use touch command to create if log.txt does not exist
os.Create("log/Installationlog.txt")
logFile, err := os.OpenFile("log/Installationlog.txt", os.O_WRONLY, 0666)
if err != nil {
panic(err)
}
defer logFile.Close()
// direct all log messages to log.txt
log.SetOutput(logFile)
log.Println("ERROR::First log message!")
install()
update()
}
我的代码的输出是
2016/01/18 13:30:51 ERROR::First log message! 2016/01/18 13:30:51 1 install 2016/01/18 13:30:51 1 install 2016/01/18 13:30:51 1 install 2016/01/18 13:30:51 1 install 2016/01/18 13:30:51 1 update 2016/01/18 13:30:51 1 update 2016/01/18 13:30:51 1 update 2016/01/18 13:30:51 1 update
全部在一行中,我希望它们每个都在单独的行中
慕工程0101907
相关分类