日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
創(chuàng)新互聯(lián)IRIS教程:iris應(yīng)用程序文件Logger

該功能是為了將日志寫(xiě)入到本地文件中

色尼網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,色尼網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為色尼近1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢(qián),請(qǐng)找那個(gè)售后服務(wù)好的色尼做網(wǎng)站的公司定做!

func main() {
    app := iris.Default()
    // Logging to a file.
    // Colors are automatically disabled when writing to a file.
    f, _ := os.Create("iris.log")
    app.Logger().SetOutput(f)

    app.Get("/ping", func(ctx iris.Context) {
        ctx.WriteString("pong")
    })

   app.Listen(":8080")
}

如果需要將日志輸出到終端,請(qǐng)使用以下代碼

app.Logger().AddOutput(os.Stdout)

控制日志輸出顏色

默認(rèn)情況下,控制臺(tái)上的日志輸出應(yīng)根據(jù)檢測(cè)到的 TTY 進(jìn)行著色。

自定義標(biāo)題、文本、顏色和樣式。

導(dǎo)入 ?GOlog 和?pio?:

import (
    "github.com/kataras/golog"
    "github.com/kataras/pio"
    // [...]
)

獲得一個(gè)自定義級(jí)別,例如調(diào)試級(jí)別(DebugLevel):

level := golog.Levels[golog.DebugLevel]

你可以完全控制他的文字、標(biāo)題和風(fēng)格:

// The Name of the Level
// that named (lowercased) will be used
// to convert a string level on `SetLevel`
// to the correct Level type.
Name string
// AlternativeNames are the names that can be referred to this specific log level.
// i.e Name = "warn"
// AlternativeNames = []string{"warning"}, it's an optional field,
// therefore we keep Name as a simple string and created this new field.
AlternativeNames []string
// Tha Title is the prefix of the log level.
// See `ColorCode` and `Style` too.
// Both `ColorCode` and `Style` should be respected across writers.
Title string
// ColorCode a color for the `Title`.
ColorCode int
// Style one or more rich options for the `Title`.
Style []pio.RichOption

示例代碼

level := golog.Levels[golog.DebugLevel]
level.Name = "debug" // default
level.Title = "[DBUG]" // default
level.ColorCode = pio.Yellow // default

更改輸出格式:

app.Logger().SetFormat("json", "    ")

注冊(cè)自定義格式化程序:

app.Logger().RegisterFormatter(new(myFormatter))

?golog.Formatter?接口如下所示:

// Formatter is responsible to print a log to the logger's writer.
type Formatter interface {
    // The name of the formatter.
    String() string
    // Set any options and return a clone,
    // generic. See `Logger.SetFormat`.
    Options(opts ...interface{}) Formatter
    // Writes the "log" to "dest" logger.
    Format(dest io.Writer, log *Log) bool
}

更改每個(gè)級(jí)別的輸出和格式:

app.Logger().SetLevelOutput("error", os.Stderr)
app.Logger().SetLevelFormat("json")

網(wǎng)站名稱(chēng):創(chuàng)新互聯(lián)IRIS教程:iris應(yīng)用程序文件Logger
標(biāo)題網(wǎng)址:http://www.dlmjj.cn/article/dpjdseg.html