logx-basic

command
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 5 Imported by: 0

README

logx basic example

最小可运行示例,展示 logx 的核心用法。

运行

go run ./examples/logx-basic

预期输出

time=2026-... level=INFO msg="service started" service=aihub env=dev version=v1.0.0 addr=:8000
time=2026-... level=DEBUG msg="querying skill" service=aihub env=dev version=v1.0.0 module=skill_repo id=skill_001
...
current level: info
after SetLevel(debug): debug
noop enabled? false

这个示例展示了什么

  1. Bootstraplogx.New(cfg) 返回 Logger + LevelController
  2. DefaultConfig:dev 模式用 console 格式,AddSource=true
  3. 结构化字段logx.String / logx.Int / logx.Err
  4. Named loggerlogger.Named("skill_repo") 添加 module 标签
  5. With 持久字段logger.With(...) 返回带固定字段的新 logger
  6. Error 日志logx.Err(err) 自动提取错误类型信息
  7. Context 注入logx.Inject + logx.FromContext 实现请求级字段
  8. 预置 helperLogExternalCall / LogAuditHint
  9. 动态级别LevelController.SetLevel("debug") 运行时调整
  10. Noop loggerlogx.Noop() 用于禁用场景或测试

下一步

如果要看 HTTP access log + panic recovery 完整示例,跑 examples/logx-http

go run ./examples/logx-http

它展示了 logx 在真实 HTTP 服务中的端到端用法。

相关文档

  • logx/README.md — 完整用户指南
  • docs/ai/logx.md — AI 编码食谱(10 场景)
  • logx/example_test.go — 所有 API 的 Go 标准 Example
  • logx/example_business_test.go — 10 个完整业务场景

Documentation

Overview

Package main demonstrates logx basic usage.

Run:

go run ./examples/logx-basic

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL