代码拉取完成,页面将自动刷新
package main
import (
"os"
"time"
"gitee.com/menciis/logx"
)
func main() {
f := newLogFile()
defer f.Close()
logx.AddOutput(f)
logx.Println("This is a raw message, no levels, no colors.")
logx.Info("This is an info message, without colors because one of the Outputs is not a terminal-based")
logx.Warn("This is a warning message")
logx.Error("This is an error message")
}
// get a filename based on the date, file logs works that way the most times
// but these are just a sugar.
func todayFilename() string {
today := time.Now().Format("Jan 02 2006")
return today + ".txt"
}
func newLogFile() *os.File {
filename := todayFilename()
// open an output file, this will append to the today's file if server restarted.
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
panic(err)
}
return f
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。