go 标准库log使用

package main

import (
    "log"
    "os"
    "io/ioutil"
    "io"
)

var (
    Trace   *log.Logger
    Info    *log.Logger
    Warning *log.Logger
    Error   *log.Logger
)

func init() {
    file, err := os.OpenFile("error.txt", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
    if err != nil {
        log.Fatalln("Fatal to open error log file:", err)
    }

    Trace = log.New(ioutil.Discard,
        "Trace: ",
        log.Ldate|log.Ltime|log.Lshortfile)

    Info = log.New(os.Stdout,
        "Info: ",
        log.Ldate|log.Ltime|log.Lshortfile)

    Warning = log.New(os.Stdout,
        "Warning: ",
        log.Ldate|log.Ltime|log.Lshortfile)

    Error = log.New(io.MultiWriter(file, os.Stderr),
        "Error: ",
        log.Ldate|log.Ltime|log.Lshortfile)
}

func main() {
    Trace.Println("this is  Trace")

    Info.Println("this is Info")

    Warning.Println("this is Warning")

    Error.Println("this is Errer")

}