代码
package main
import (
"log"
"os"
)
/*
2016/10/20 13:25:42 Hello, 5 + 3 = 8
[bar]2016/10/20 13:25:42 test.go:29: Hello, world!
[bar]2016/10/20 13:25:42 test.go:30: Hello, world!
[bar]2016/10/20 13:25:42 test.go:31: 5 + 3 = 8
[bar]2016/10/20 13:25:42 test.go:33: Program will exit from here.
exit status 1
*/
func main() {
foo()
bar()
}
func foo() {
log.Println("Hello, 5 + 3 = ", 5 + 3)
}
func bar() {
logger := log.New(os.Stdout, "[bar]", log.Lshortfile | log.Ldate | log.Ltime)
logger.Println("Hello, world!")
logger.Println("Hello, ", "world!")
logger.Printf("5 + 3 = %d\n", 5 + 3)
logger.Fatal("Program will exit from here.")
logger.Println("Unreachable code.")
}
有疑问加站长微信联系(非本文作者)