<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                日志處理 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"}`) 詳細更多日志的請配置查看日志配置 這個默認情況就會同時輸出到兩個地方,一個控制臺,一個文件,如果只想輸出到文件,就需要調用刪除操作: beego.BeeLogger.DelLogger("console") 設置級別 日志的級別如上所示的代碼這樣分為八個級別: ~~~ LevelEmergency LevelAlert LevelCritical LevelError LevelWarning LevelNotice LevelInformational LevelDebug ~~~ 級別依次降低,默認全部打印,但是一般我們在部署環境,可以通過設置級別設置日志級別: beego.SetLevel(beego.LevelInformational) 輸出文件名和行號 日志默認不輸出調用的文件名和文件行號,如果你期望輸出調用的文件名和文件行號,可以如下設置 beego.SetLogFuncCall(true) 開啟傳入參數true,關閉傳入參數false,默認是關閉的。 示例代碼: 創建logs文件夾 project.log 文件 ~~~ project | |-- logs | `-- project.log ~~~ ~~~ project |-- conf | `-- app.conf ~~~ ~~~ appname = project httpport = 8080 runmode = dev #關閉自動渲染 autorender = false ~~~ ~~~ |-- routers | `-- router.go ~~~ ~~~ package routers import ( admin "project/admin/controllers" "github.com/astaxie/beego" ) func init() { // 固定路由也就是全匹配的路由 beego.Router("/admin/user/index", &admin.UserController{}, "*:Index") } ~~~ ~~~ |-- admin | |--controllers | `-- user.go ~~~ ~~~ package admin import ( "github.com/astaxie/beego" ) type UserController struct { beego.Controller } func (this *UserController) Index() { // 正式環境 日志配置根據需求在 beego.Run() 之前配置 // 日志配置 beego.SetLogger("file", `{"filename":"logs/project.log"}`) // 設置級別 beego.SetLevel(beego.LevelDebug) // 輸出文件名和行號 beego.SetLogFuncCall(true) // 寫入日志 beego.Debug("this is debug") beego.Informational("this is informational") beego.Notice("this is notice") beego.Warning("this is warning") beego.Error("this is error") beego.Critical("this is critical") beego.Alert("this is alert") beego.Emergency("this is emergency") this.Ctx.WriteString("Run to the end") } ~~~ 瀏覽器訪問: http://127.0.0.1:8080/admin/user/index 查看 logs/project.log ~~~ 2018/04/20 11:10:40 [D] [user.go:19] this is debug 2018/04/20 11:10:40 [I] [user.go:20] this is informational 2018/04/20 11:10:40 [N] [user.go:21] this is notice 2018/04/20 11:10:40 [W] [user.go:22] this is warning 2018/04/20 11:10:40 [E] [user.go:23] this is error 2018/04/20 11:10:40 [C] [user.go:24] this is critical 2018/04/20 11:10:40 [A] [user.go:25] this is alert 2018/04/20 11:10:40 [M] [user.go:26] this is emergency 2018/04/20 11:10:40 [D] [server.go:2610] | 127.0.0.1| 200 | 1.349317ms| match| GET  /admin/user/index r:/admin/user/index ~~~
                  <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>

                              哎呀哎呀视频在线观看