直接上代码:
package mylog
import (
"log"
"os"
)
var (
Debug *log.Logger
Info *log.Logger
Error *log.Logger
)
func init() {
log.Println("init ...")
Debug = log.New(os.Stdout, "[DEBUG] ", log.Ldate|log.Ltime|log.Lshortfile)
Info = log.New(os.Stdout, "[INFO] ", log.Ldate|log.Ltime|log.Lshortfile)
Error = log.New(os.Stderr, "[ERROR] ", log.Ldate|log.Ltime|log.Lshortfile)
}
package main
import "mylog"
func main(){
mylog.Debug.Println("good");
mylog.Info.Println("good");
mylog.Error.Println("good");
}
就这样。