1 Star 1 Fork 1

menuiis/logx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 858 Bytes
一键复制 编辑 原始数据 按行查看 历史
menuis 提交于 2年前 . init
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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/menciis/logx.git
git@gitee.com:menciis/logx.git
menciis
logx
logx
master

搜索帮助