go language logging library simple use method example analysis


This article illustrates the simple use of the go language logging library. Share with you for your reference. The specific implementation method is as follows:

package main
import (
 "fmt"
 "log"
 "os"
)
func main(){
 logfile,err := os.OpenFile("/var/golang/ofstack.com.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");
}

I hope this article has been helpful to your programming of Go language.