首页 > 其他 > 详细

go log

时间:2021-06-02 09:27:31      阅读:25      评论:0      收藏:0      [点我收藏+]
package main

import (
	"log"
	"os"
)

var (
    Info *log.Logger
    Warning *log.Logger
    Error * log.Logger
)
func main(){
	logFile,error:=os.OpenFile("./log.log",os.O_CREATE|os.O_WRONLY|os.O_APPEND,0644)
  if error!=nil {
    log.Fatalln("打开日志文件失败")
  }
  defer logFile.Close()
  Info = log.New(logFile,"Info:",log.Ldate | log.Ltime | log.Llongfile)
  Warning = log.New(logFile,"Warning:",log.Ldate | log.Ltime | log.Llongfile)
  Error = log.New(logFile,"Error:",log.Ldate | log.Ltime | log.Llongfile)
  Info.Output(1,"这是info")
  Warning.Output(1,"warning")
  Error.Output(1,"error")

}

  

go log

原文:https://www.cnblogs.com/HHMLXL/p/14839141.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!