第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

來(lái)自 GitHub.com/Shopify/sarama 的測(cè)試日志輸出

來(lái)自 GitHub.com/Shopify/sarama 的測(cè)試日志輸出

Go
qq_笑_17 2022-07-04 16:08:05
github.com/Shopify/sarama我正在嘗試為 configure's的功能選項(xiàng)編寫(xiě)單元測(cè)試Logger。像這樣使用 Kafka 運(yùn)行 Docker 容器后,docker run -p 2181:2181 -p 9092:9092 -e ADVERTISED_HOST=127.0.0.1  -e NUM_PARTITIONS=10 johnnypark/kafka-zookeeper我正在嘗試運(yùn)行這個(gè)程序:package mainimport (    "bufio"    "bytes"    "io/ioutil"    "log"    "github.com/Shopify/sarama")func main() {    var b bytes.Buffer    out := bufio.NewWriter(&b)    sarama.Logger = log.New(out, "[Sarama] ", log.LstdFlags)    if _, err := sarama.NewClient([]string{"localhost:9092"}, sarama.NewConfig()); err != nil {        log.Fatalln("NewClient:", err)    }    output, err := ioutil.ReadAll(&b)    if err != nil {        log.Fatalln("ReadAll:", err)    }    log.Printf("output: %s", output)}我希望看到一些輸出。但是,打印輸出為空:> go run main.go2020/09/25 16:44:58 output: 相比之下,如果我將輸出設(shè)置os.Stderr為package mainimport (    "log"    "os"    "github.com/Shopify/sarama")func main() {    sarama.Logger = log.New(os.Stderr, "[Sarama] ", log.LstdFlags)    if _, err := sarama.NewClient([]string{"localhost:9092"}, sarama.NewConfig()); err != nil {        log.Fatalln("NewClient:", err)    }}我看到打印到終端的預(yù)期輸出:> go run main.go[Sarama] 2020/09/25 16:46:04 Initializing new client[Sarama] 2020/09/25 16:46:04 ClientID is the default of 'sarama', you should consider setting it to something application-specific.[Sarama] 2020/09/25 16:46:04 ClientID is the default of 'sarama', you should consider setting it to something application-specific.[Sarama] 2020/09/25 16:46:04 client/metadata fetching metadata for all topics from broker localhost:9092[Sarama] 2020/09/25 16:46:04 Connected to broker at localhost:9092 (unregistered)[Sarama] 2020/09/25 16:46:04 client/brokers registered new broker #0 at 127.0.0.1:9092[Sarama] 2020/09/25 16:46:04 Successfully initialized new client似乎*bytes.Buffer沒(méi)有被“沖走” ioutil.ReadAll()?如何修復(fù)前面的示例,使其output不為空?
查看完整描述

1 回答

?
慕的地8271018

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊

原來(lái)我只需要打電話


out.Flush()

之前ioutil.ReadAll()?,F(xiàn)在輸出如預(yù)期:


> go run main.go

2020/09/25 16:58:26 output: [Sarama] 2020/09/25 16:58:26 Initializing new client

[Sarama] 2020/09/25 16:58:26 ClientID is the default of 'sarama', you should consider setting it to something application-specific.

[Sarama] 2020/09/25 16:58:26 ClientID is the default of 'sarama', you should consider setting it to something application-specific.

[Sarama] 2020/09/25 16:58:26 client/metadata fetching metadata for all topics from broker localhost:9092

[Sarama] 2020/09/25 16:58:26 Connected to broker at localhost:9092 (unregistered)

[Sarama] 2020/09/25 16:58:26 client/brokers registered new broker #0 at 127.0.0.1:9092

[Sarama] 2020/09/25 16:58:26 Successfully initialized new client


查看完整回答
反對(duì) 回復(fù) 2022-07-04
  • 1 回答
  • 0 關(guān)注
  • 317 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)