本文实例讲述了go语言日志记录库简单使用方法。分享给大家供大家参考。具体实现方法如下:
复制代码 代码如下:
package main
import (
"fmt"
"log"
"os"
)
func main(){
logfile,err := os.OpenFile("/var/golang/jb51.net.log",os.O_RDWR|os.O_CREATE,0);
if err!=nil {
fmt.Printf("%s\r\n",err.Error());
os.Exit(-1);
}
defer logfile.Close();
logger := log.New(logfile,"\r\n",log.Ldate|log.Ltime|log.Llongfile);
logger.Println("hello");
logger.Println("oh....");
logger.Fatal("test");
logger.Fatal("test2");
}
import (
"fmt"
"log"
"os"
)
func main(){
logfile,err := os.OpenFile("/var/golang/jb51.net.log",os.O_RDWR|os.O_CREATE,0);
if err!=nil {
fmt.Printf("%s\r\n",err.Error());
os.Exit(-1);
}
defer logfile.Close();
logger := log.New(logfile,"\r\n",log.Ldate|log.Ltime|log.Llongfile);
logger.Println("hello");
logger.Println("oh....");
logger.Fatal("test");
logger.Fatal("test2");
}
希望本文所述对大家的Go语言程序设计有所帮助。