go語言log包的學習(log,Logger)

來源:互聯網
上載者:User

標籤:exit   int   學習   tde   首碼   基於   Go語言   fatal   函數   

package main;import ("log""os""time""fmt")func main() {//建立輸出記錄檔logFile, err := os.Create("./" + time.Now().Format("20060102") + ".txt");if err != nil {fmt.Println(err);}//建立一個Logger//參數1:日誌寫入目的地//參數2:每條日誌的首碼//參數3:日誌屬性loger := log.New(logFile, "test_", log.Ldate|log.Ltime|log.Lshortfile);//Flags返回Logger的輸出選項fmt.Println(loger.Flags());//SetFlags設定輸出選項loger.SetFlags(log.Ldate | log.Ltime | log.Lshortfile);//返回輸出首碼fmt.Println(loger.Prefix());//設定輸出首碼loger.SetPrefix("test_");//輸出一條日誌loger.Output(2, "列印一條日誌資訊");//格式化輸出日誌loger.Printf("第%d行 內容:%s", 11, "我是錯誤");//等價於print();os.Exit(1);loger.Fatal("我是錯誤");//等價於print();panic();loger.Panic("我是錯誤");//log的匯出函數//匯出函數基於std,std是標準錯誤輸出//var std = New(os.Stderr, "", LstdFlags)//擷取輸出項fmt.Println(log.Flags());//擷取首碼fmt.Printf(log.Prefix());//輸出內容log.Output(2, "輸出內容");//格式化輸出log.Printf("第%d行 內容:%s", 22, "我是錯誤");log.Fatal("我是錯誤");log.Panic("我是錯誤");}

  

go語言log包的學習(log,Logger)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.