dongpi9494 2016-12-30 06:25
浏览 142
已采纳

为什么在使用`log.Println`和`fmt.Println`时改变输出顺序?

Here is my code: package main

import "log"
import "fmt"

func main() {
    var a string = "initail"
    log.Println(a)
    var b, c int = 1, 2
    fmt.Println(b, c)
}

The output is:

1 2
2016/12/30 14:22:58 initail

So i don't understand why the output's order? why log.Println is slower than fmt.Println?

  • 写回答

1条回答 默认 最新

  • dqu94359 2016-12-30 06:42
    关注

    Only difference between those in terms of its printing behaviour is

    • log.Println writes to Stderr
    • fmt.Println writes to Stdout

    Both are not buffered. So the fact that StdOut came before StdError is specific to your terminal or environment.

    Here is a play link https://play.golang.org/p/0cukg_a9GR

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?