函数式编程
记录器不应该知道如何刷新数据。您必须刷新您在创建记录器时指定的输出编写器(如果它具有这种功能)。package mainimport ( "bufio" "flag" "log" "os" "strings")func main() { var flush bool flag.BoolVar(&flush, "flush", false, "if set, will flush the buffered io before exiting") flag.Parse() br := bufio.NewWriter(os.Stdout) logger := log.New(br, "", log.Ldate) logger.Printf("%s\n", strings.Repeat("This is a test\n", 5)) if flush { br.Flush() } logger.Fatalf("exiting now!")}