From c2ec1e751371e11becb2d3360bd3548477b5fbde Mon Sep 17 00:00:00 2001 From: pppscn <35696959@qq.com> Date: Tue, 5 Jan 2021 19:38:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=97=A5=E5=BF=97=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E5=88=B0=E6=8E=A7=E5=88=B6=E5=8F=B0=E5=92=8C?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.go b/main.go index 1dd52b9..097731c 100644 --- a/main.go +++ b/main.go @@ -5,12 +5,26 @@ import ( "github.com/unknwon/goconfig" "github.com/ztino/jd_seckill/cmd" "github.com/ztino/jd_seckill/common" + "io" "log" "os" "runtime" + "time" ) func init() { + //将日志同时输出到控制台和文件 + file := "./" + "jd_seckill_" + time.Now().Format("20060102") + ".log" + logFile, logErr := os.OpenFile(file, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666) + if logErr != nil { + panic(logErr) + } + defer logFile.Close() + mw := io.MultiWriter(os.Stdout, logFile) + log.SetOutput(mw) + log.SetPrefix("[jd_seckill]") + log.SetFlags(log.LstdFlags | log.Lshortfile | log.LUTC) + //客户端设置初始化 common.Client=httpc.NewHttpClient() common.CookieJar=httpc.NewCookieJar() @@ -26,6 +40,7 @@ func init() { //抢购状态管道 common.SeckillStatus=make(chan bool) + log.Println("jd_seckill 程序启动成功,祝您成功!") } func main() {