PageSourceSearch

https://www.mcube.top/static/js/async/7971.10afd398.js

js mcube.top collected 2026-10-05 01:10:56 UTC 5,766 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["7971"],{7171:function(e,n,r){r.r(n),r.d(n,{default:()=>s});var o=r(5893),l=r(65),a=r(6897);function g(e){let n=Object.assign({h1:"h1",a:"a",p:"p",ul:"ul",li:"li",h2:"h2",pre:"pre",code:"code",h3:"h3"},(0,l.ah)(),e.components);return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.h1,{id:"log",children:[(0,o.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#log",children:"#"}),"Log"]}),"\n",(0,o.jsx)(n.p,{children:"常见的功能比较完善的日志库有:"}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.a,{href:"https://github.com/rs/zerolog",rel:"noopener noreferrer",target:"_blank",children:"zerolog"}),": 注重性能和低开销,采用结构化日志,适合对性能要求极高的场景"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.a,{href:"https://github.com/sirupsen/logrus",rel:"noopener noreferrer",target:"_blank",children:"logrus"}),": 功能丰富且易于使用,支持多种输出格式和钩子,适合快速集成"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.a,{href:"https://github.com/uber-go/zap",rel:"noopener noreferrer",target:"_blank",children:"zap"}),": 高性能且灵活,提供结构化日志和多种级别的日志记录,适合需要高吞吐量的应用"]}),"\n"]}),"\n",(0,o.jsx)(n.p,{children:"以上3中日志库都使用过, 综合性能和使用体验上来说 zerolog 最佳, 因此打算支持: + zerolog: 性能和使用体验上由于其他2个"}),"\n",(0,o.jsxs)(n.h2,{id:"默认配置",children:[(0,o.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#默认配置",children:"#"}),"默认配置"]}),"\n",(0,o.jsxs)(a.mQ,{children:[(0,o.jsx)(a.OK,{label:"toml",children:(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-toml",children:'[log]\n# 0 为打印日志全路径, 默认打印2层路径\ncaller_deep = 3\n# 日志的级别, 默认Debug\nlevel = "debug"\n# 开启Trace时, 记录的TraceId名称, 默认trace_id\ntrace_filed = "trace_id"\n\n[log.console]\nenable = true\nno_color = false\n\n[log.file]\n# 是否开启文件记录\nenable = false\n# 文件的路径\nfile_path = ""\n# 单位M, 默认100M\nmax_size = 100\n# 默认保存 6个文件\nmax_backups = 6\n# 保存多久\nmax_age = 0\n# 是否压缩\ncompress = false\n\n'})})}),(0,o.jsx)(a.OK,{label:"env",children:(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:'LOG_CALLER_DEEP=3\nLOG_LEVEL="debug"\nLOG_TRACE_FILED="trace_id"\n\nLOG_CONSOLE_ENABLE=true\nLOG_CONSOLE_NO_COLOR=false\n\nLOG_FILE_ENABLE=false\nLOG_FILE_PATH=""\nLOG_FILE_MAX_SIZE=100\nLOG_FILE_MAX_BACKUPS=6\nLOG_FILE_MAX_AGE=0\nLOG_FILE_COMPRESS=false\n'})})})]}),"\n",(0,o.jsxs)(n.p,{children:["更详细的信息请查看",(0,o.jsx)(n.a,{href:"https://github.com/infraboard/mcube/blob/master/ioc/config/logger/log.go#L89-L99",rel:"noopener noreferrer",target:"_blank",children:"源码"})]}),"\n",(0,o.jsxs)(n.h2,{id:"基本使用",children:[(0,o.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#基本使用",children:"#"}),"基本使用"]}),"\n",(0,o.jsxs)(n.h3,{id:"global-logger",children:[(0,o.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#global-logger",children:"#"}),"Global Logger"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-go",children:'package main\n\nimport (\n	"github.com/infraboard/mcube/v2/ioc"\n	"github.com/infraboard/mcube/v2/ioc/config/log"\n)\n\nfunc main() {\n	ioc.DevelopmentSetup()\n\n	gLogger := log.L()\n	glog.Debug().Msg("this is global logger debug msg")\n}\n'})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:"2023-12-24T17:44:30+08:00 DEBUG  examples/log/main.go:12 > this is global logger debug msg\n"})}),"\n",(0,o.jsxs)(n.h3,{id:"sub-logger",children:[(0,o.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#sub-logger",children:"#"}),"Sub Logger"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-go",children:'package main\n\nimport (\n	"github.com/infraboard/mcube/v2/ioc"\n	"github.com/infraboard/mcube/v2/ioc/config/log"\n)\n\nfunc main() {\n	ioc.DevelopmentSetup()\n\n	subLogger := log.Sub("app1")\n	sublog.Debug().Msg("this is app1 sub logger debug msg")\n}\n'})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:"2023-12-24T
117:44:30+08:00 DEBUG  examples/log/main.go:15 > this is app1 sub logger debug msg component:APP1\n"})}),"\n",(0,o.jsxs)(n.h3,{id:"context-logger",children:[(0,o.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#context-logger",children:"#"}),"Context Logger"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-go",children:'package main\n\nimport (\n	"context"\n\n	"github.com/infraboard/mcube/v2/ioc"\n	"github.com/infraboard/mcube/v2/ioc/config/log"\n)\n\nfunc main() {\n	ioc.DevelopmentSetup()\n\n	log.FromCtx(c.Request.Context()).Info().Msgf("debug log")\n}\n'})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:"2023-12-24T17:47:02+08:00 DEBUG  examples/log/main.go:21 > this is app1 trace logger debug msg component:APP1 trace_id:00000000000000000000000000000000\n"})})]})}function i(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:n}=Object.assign({},(0,l.ah)(),e.components);return n?(0,o.jsx)(n,Object.assign({},e,{children:(0,o.jsx)(g,e)})):g(e)}let s=i;i.__RSPRESS_PAGE_META={},i.__RSPRESS_PAGE_META["guide%2Fconfig%2Flog.mdx"]={toc:[{id:"默认配置",text:"默认配置",depth:2},{id:"基本使用",text:"基本使用",depth:2},{id:"global-logger",text:"Global Logger",depth:3},{id:"sub-logger",text:"Sub Logger",depth:3},{id:"context-logger",text:"Context Logger",depth:3}],title:"Log",headingTitle:"Log",frontmatter:{}}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.