<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 日志處理 beego 之前介紹的時候說過是基于幾個模塊搭建的,beego 的日志處理是基于 logs 模塊搭建的,內置了一個變量 `BeeLogger`,默認已經是 `logs.BeeLogger` 類型,初始化了 console,也就是默認輸出到 `console`。 ## 使用入門 一般在程序中我們使用如下的方式進行輸出: beego.Emergency("this is emergency") beego.Alert("this is alert") beego.Critical("this is critical") beego.Error("this is error") beego.Warning("this is warning") beego.Notice("this is notice") beego.Informational("this is informational") beego.Debug("this is debug") ## 設置輸出 我們的程序往往期望把信息輸出到 log 中,現在設置輸出到文件很方便,如下所示: beego.SetLogger("file", `{"filename":"logs/test.log"}`) 更多詳細的日志配置請查看 [日志配置](../../module/logs.md) 這個默認情況就會同時輸出到兩個地方,一個 console,一個 file,如果只想輸出到文件,就需要調用刪除操作: beego.BeeLogger.DelLogger("console") ## 設置級別 日志的級別如上所示的代碼這樣分為八個級別: LevelEmergency LevelAlert LevelCritical LevelError LevelWarning LevelNotice LevelInformational LevelDebug 級別依次降低,默認全部打印,但是一般我們在部署環境,可以通過設置級別設置日志級別: beego.SetLevel(beego.LevelInformational) ## 輸出文件名和行號 日志默認不輸出調用的文件名和文件行號,如果你期望輸出調用的文件名和文件行號,可以如下設置 beego.SetLogFuncCall(true) 開啟傳入參數 true, 關閉傳入參數 false, 默認是關閉的. ## 完整示例 ```go func internalCalculationFunc(x, y int) (result int, err error) { beego.Debug("calculating z. x:", x, " y:", y) z := y switch { case x == 3: beego.Debug("x == 3") panic("Failure.") case y == 1: beego.Debug("y == 1") return 0, errors.New("Error!") case y == 2: beego.Debug("y == 2") z = x default: beego.Debug("default") z += x } retVal := z - 3 beego.Debug("Returning ", retVal) return retVal, nil } func processInput(input inputData) { defer func() { if r := recover(); r != nil { beego.Error("Unexpected error occurred: ", r) outputs <- outputData{result: 0, error: true} } }() beego.Informational("Received input signal. x:", input.x, " y:", input.y) res, err := internalCalculationFunc(input.x, input.y) if err != nil { beego.Warning("Error in calculation:", err.Error()) } beego.Informational("Returning result: ", res, " error: ", err) outputs <- outputData{result: res, error: err != nil} } func main() { inputs = make(chan inputData) outputs = make(chan outputData) criticalChan = make(chan int) beego.Informational("App started.") go consumeResults(outputs) beego.Informational("Started receiving results.") go generateInputs(inputs) beego.Informational("Started sending signals.") for { select { case input := <-inputs: processInput(input) case <-criticalChan: beego.Critical("Caught value from criticalChan: Go shut down.") panic("Shut down due to critical fault.") } } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看