Go語言(log4go介紹)

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

今天來介紹一個Go語言中常用的日誌第三方包,即log4go。在C++中,有log4cpp,而在Java中,有log4j。

 

好了,廢話不多說,現在就來介紹log4go的使用。在log4go在github上的連結如下

 

連結:https://github.com/skoo87/log4go

 

具體用法可以參考examples檔案夾,而且設定檔採用JSON的格式。一個典型的例子如下

 

log.json:

{    "LogLevel" : "info",    "FileWriter" : {        "LogPath" : "log-%Y%M%D.log",        "On": true    },    "ConsoleWriter" : {        "On" : true    }}


main.go:

package mainimport (log "github.com/skoo87/log4go")func main() {if err := log.SetupLogWithConf("../src/conf/log.json"); err != nil {panic(err)}defer log.Close()var name = "skoo"log.Debug("log4go by %s", name)log.Info("log4go by %s", name)log.Warn("log4go by %s", name)log.Error("log4go by %s", name)log.Fatal("log4go by %s", name)}

 

建立的項目如下結構

 

 

 

在src目錄下進行編譯,如下

 

 

 

然後在項目根目錄log4go下就得到了bin檔案夾,裡面有可執行檔,執行這個檔案,如下

 

 

 

同時也得到了日誌輸出檔案,如下結構

 

 

 

好了,如果想參考log4go的更多內容,examples檔案夾下有很多,路徑如下

 

 examples路徑:log4go/src/github.com/skoo87/log4go/examples

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.