ai-engineering-init 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/code-reviewer.md +139 -0
- package/.claude/agents/project-manager.md +159 -0
- package/.claude/audio/completed.wav +0 -0
- package/.claude/commands/add-todo.md +255 -0
- package/.claude/commands/check.md +210 -0
- package/.claude/commands/crud.md +454 -0
- package/.claude/commands/dev.md +503 -0
- package/.claude/commands/init-docs.md +681 -0
- package/.claude/commands/next.md +251 -0
- package/.claude/commands/progress.md +242 -0
- package/.claude/commands/start.md +199 -0
- package/.claude/commands/sync.md +307 -0
- package/.claude/commands/update-status.md +428 -0
- package/.claude/docs/Mixin/344/275/277/347/224/250/346/214/207/345/215/227.md +299 -0
- package/.claude/docs/README.md +167 -0
- package/.claude/docs//345/211/215/347/253/257/345/274/200/345/217/221/346/214/207/345/215/227.md +599 -0
- package/.claude/docs//345/220/216/347/253/257/345/274/200/345/217/221/346/214/207/345/215/227.md +726 -0
- package/.claude/docs//345/267/245/344/275/234/346/265/201/345/274/200/345/217/221/346/214/207/345/215/227.md +714 -0
- package/.claude/docs//345/267/245/345/205/267/347/261/273/344/275/277/347/224/250/346/214/207/345/215/227.md +463 -0
- package/.claude/docs//346/225/260/346/215/256/345/272/223/350/256/276/350/256/241/350/247/204/350/214/203.md +390 -0
- package/.claude/docs//346/226/260/345/212/237/350/203/275/345/274/200/345/217/221/346/265/201/347/250/213/350/247/204/350/214/203.md +688 -0
- package/.claude/docs//346/226/260/351/241/271/347/233/256/345/274/200/345/217/221/346/265/201/347/250/213.md +365 -0
- package/.claude/docs//346/241/206/346/236/266/350/257/264/346/230/216.md +393 -0
- package/.claude/docs//350/267/257/347/224/261/351/205/215/347/275/256/346/214/207/345/215/227.md +246 -0
- package/.claude/framework-config.json +73 -0
- package/.claude/hooks/pre-tool-use.js +117 -0
- package/.claude/hooks/skill-forced-eval.js +167 -0
- package/.claude/hooks/stop.js +58 -0
- package/.claude/settings.json +41 -0
- package/.claude/skills/add-skill/SKILL.md +352 -0
- package/.claude/skills/api-development/SKILL.md +560 -0
- package/.claude/skills/architecture-design/SKILL.md +756 -0
- package/.claude/skills/backend-annotations/SKILL.md +674 -0
- package/.claude/skills/banana-image/CHANGELOG.md +37 -0
- package/.claude/skills/banana-image/README.md +146 -0
- package/.claude/skills/banana-image/SKILL.md +164 -0
- package/.claude/skills/banana-image/assets/logo.png +0 -0
- package/.claude/skills/banana-image/references/advanced-usage.md +189 -0
- package/.claude/skills/banana-image/scripts/apply_template.py +125 -0
- package/.claude/skills/banana-image/scripts/banana_image_exec.ts +412 -0
- package/.claude/skills/banana-image/scripts/batch_prep.py +82 -0
- package/.claude/skills/banana-image/scripts/package-lock.json +1437 -0
- package/.claude/skills/banana-image/scripts/package.json +18 -0
- package/.claude/skills/banana-image/scripts/requirements.txt +10 -0
- package/.claude/skills/banana-image/templates/poster.json +22 -0
- package/.claude/skills/banana-image/templates/product.json +17 -0
- package/.claude/skills/banana-image/templates/social.json +22 -0
- package/.claude/skills/banana-image/templates/thumbnail.json +17 -0
- package/.claude/skills/brainstorm/SKILL.md +648 -0
- package/.claude/skills/bug-detective/SKILL.md +1206 -0
- package/.claude/skills/code-patterns/SKILL.md +590 -0
- package/.claude/skills/collaborating-with-codex/SKILL.md +174 -0
- package/.claude/skills/collaborating-with-codex/scripts/codex_bridge.py +275 -0
- package/.claude/skills/collaborating-with-gemini/SKILL.md +194 -0
- package/.claude/skills/collaborating-with-gemini/scripts/gemini_bridge.py +275 -0
- package/.claude/skills/crud-development/SKILL.md +649 -0
- package/.claude/skills/data-permission/SKILL.md +599 -0
- package/.claude/skills/database-ops/SKILL.md +407 -0
- package/.claude/skills/error-handler/SKILL.md +371 -0
- package/.claude/skills/file-oss-management/SKILL.md +863 -0
- package/.claude/skills/git-workflow/SKILL.md +375 -0
- package/.claude/skills/json-serialization/SKILL.md +357 -0
- package/.claude/skills/leniu-api-development/SKILL.md +803 -0
- package/.claude/skills/leniu-architecture-design/SKILL.md +598 -0
- package/.claude/skills/leniu-backend-annotations/SKILL.md +664 -0
- package/.claude/skills/leniu-code-patterns/SKILL.md +365 -0
- package/.claude/skills/leniu-crud-development/SKILL.md +1110 -0
- package/.claude/skills/leniu-data-permission/SKILL.md +256 -0
- package/.claude/skills/leniu-database-ops/SKILL.md +426 -0
- package/.claude/skills/leniu-error-handler/SKILL.md +462 -0
- package/.claude/skills/leniu-java-amount-handling/SKILL.md +461 -0
- package/.claude/skills/leniu-java-code-style/SKILL.md +510 -0
- package/.claude/skills/leniu-java-concurrent/SKILL.md +400 -0
- package/.claude/skills/leniu-java-entity/SKILL.md +751 -0
- package/.claude/skills/leniu-java-export/SKILL.md +560 -0
- package/.claude/skills/leniu-java-logging/SKILL.md +832 -0
- package/.claude/skills/leniu-java-mq/SKILL.md +338 -0
- package/.claude/skills/leniu-java-mybatis/SKILL.md +640 -0
- package/.claude/skills/leniu-java-report-query-param/SKILL.md +291 -0
- package/.claude/skills/leniu-java-task/SKILL.md +367 -0
- package/.claude/skills/leniu-java-total-line/SKILL.md +195 -0
- package/.claude/skills/leniu-marketing-price-rule-customizer/SKILL.md +301 -0
- package/.claude/skills/leniu-marketing-recharge-rule-customizer/SKILL.md +285 -0
- package/.claude/skills/leniu-mealtime/SKILL.md +215 -0
- package/.claude/skills/leniu-redis-cache/SKILL.md +316 -0
- package/.claude/skills/leniu-security-guard/SKILL.md +520 -0
- package/.claude/skills/leniu-utils-toolkit/SKILL.md +380 -0
- package/.claude/skills/openspec-apply-change/SKILL.md +156 -0
- package/.claude/skills/openspec-archive-change/SKILL.md +114 -0
- package/.claude/skills/openspec-bulk-archive-change/SKILL.md +246 -0
- package/.claude/skills/openspec-continue-change/SKILL.md +118 -0
- package/.claude/skills/openspec-explore/SKILL.md +290 -0
- package/.claude/skills/openspec-ff-change/SKILL.md +101 -0
- package/.claude/skills/openspec-new-change/SKILL.md +74 -0
- package/.claude/skills/openspec-onboard/SKILL.md +529 -0
- package/.claude/skills/openspec-sync-specs/SKILL.md +138 -0
- package/.claude/skills/openspec-verify-change/SKILL.md +168 -0
- package/.claude/skills/performance-doctor/SKILL.md +627 -0
- package/.claude/skills/project-navigator/SKILL.md +305 -0
- package/.claude/skills/redis-cache/SKILL.md +839 -0
- package/.claude/skills/scheduled-jobs/SKILL.md +633 -0
- package/.claude/skills/security-guard/SKILL.md +748 -0
- package/.claude/skills/sms-mail/SKILL.md +766 -0
- package/.claude/skills/social-login/SKILL.md +668 -0
- package/.claude/skills/store-pc/SKILL.md +366 -0
- package/.claude/skills/task-tracker/SKILL.md +307 -0
- package/.claude/skills/tech-decision/SKILL.md +393 -0
- package/.claude/skills/tenant-management/SKILL.md +603 -0
- package/.claude/skills/test-development/SKILL.md +755 -0
- package/.claude/skills/ui-pc/SKILL.md +438 -0
- package/.claude/skills/utils-toolkit/SKILL.md +615 -0
- package/.claude/skills/websocket-sse/SKILL.md +716 -0
- package/.claude/skills/workflow-engine/SKILL.md +676 -0
- package/.claude/templates//345/276/205/345/212/236/346/270/205/345/215/225/346/250/241/346/235/277.md +56 -0
- package/.claude/templates//351/234/200/346/261/202/346/226/207/346/241/243/346/250/241/346/235/277.md +85 -0
- package/.claude/templates//351/241/271/347/233/256/347/212/266/346/200/201/346/250/241/346/235/277.md +43 -0
- package/.codex/skills/add-skill/SKILL.md +352 -0
- package/.codex/skills/add-todo/SKILL.md +269 -0
- package/.codex/skills/api-development/SKILL.md +693 -0
- package/.codex/skills/architecture-design/SKILL.md +628 -0
- package/.codex/skills/backend-annotations/SKILL.md +664 -0
- package/.codex/skills/banana-image/CHANGELOG.md +37 -0
- package/.codex/skills/banana-image/README.md +146 -0
- package/.codex/skills/banana-image/SKILL.md +164 -0
- package/.codex/skills/banana-image/assets/logo.png +0 -0
- package/.codex/skills/banana-image/references/advanced-usage.md +189 -0
- package/.codex/skills/banana-image/scripts/apply_template.py +125 -0
- package/.codex/skills/banana-image/scripts/banana_image_exec.ts +412 -0
- package/.codex/skills/banana-image/scripts/batch_prep.py +82 -0
- package/.codex/skills/banana-image/scripts/package-lock.json +1437 -0
- package/.codex/skills/banana-image/scripts/package.json +18 -0
- package/.codex/skills/banana-image/scripts/requirements.txt +10 -0
- package/.codex/skills/banana-image/templates/poster.json +22 -0
- package/.codex/skills/banana-image/templates/product.json +17 -0
- package/.codex/skills/banana-image/templates/social.json +22 -0
- package/.codex/skills/banana-image/templates/thumbnail.json +17 -0
- package/.codex/skills/brainstorm/SKILL.md +648 -0
- package/.codex/skills/bug-detective/SKILL.md +1206 -0
- package/.codex/skills/check/SKILL.md +367 -0
- package/.codex/skills/code-patterns/SKILL.md +442 -0
- package/.codex/skills/collaborating-with-codex/SKILL.md +174 -0
- package/.codex/skills/collaborating-with-codex/scripts/codex_bridge.py +275 -0
- package/.codex/skills/collaborating-with-gemini/SKILL.md +194 -0
- package/.codex/skills/collaborating-with-gemini/scripts/gemini_bridge.py +275 -0
- package/.codex/skills/crud/SKILL.md +265 -0
- package/.codex/skills/crud-development/SKILL.md +637 -0
- package/.codex/skills/data-permission/SKILL.md +591 -0
- package/.codex/skills/database-ops/SKILL.md +553 -0
- package/.codex/skills/dev/SKILL.md +187 -0
- package/.codex/skills/error-handler/SKILL.md +361 -0
- package/.codex/skills/file-oss-management/SKILL.md +863 -0
- package/.codex/skills/git-workflow/SKILL.md +375 -0
- package/.codex/skills/init-docs/SKILL.md +194 -0
- package/.codex/skills/json-serialization/SKILL.md +357 -0
- package/.codex/skills/leniu-api-development/SKILL.md +803 -0
- package/.codex/skills/leniu-architecture-design/SKILL.md +594 -0
- package/.codex/skills/leniu-backend-annotations/SKILL.md +662 -0
- package/.codex/skills/leniu-code-patterns/SKILL.md +365 -0
- package/.codex/skills/leniu-crud-development/SKILL.md +1110 -0
- package/.codex/skills/leniu-data-permission/SKILL.md +256 -0
- package/.codex/skills/leniu-database-ops/SKILL.md +426 -0
- package/.codex/skills/leniu-error-handler/SKILL.md +462 -0
- package/.codex/skills/leniu-java-amount-handling/SKILL.md +461 -0
- package/.codex/skills/leniu-java-code-style/SKILL.md +510 -0
- package/.codex/skills/leniu-java-concurrent/SKILL.md +400 -0
- package/.codex/skills/leniu-java-entity/SKILL.md +751 -0
- package/.codex/skills/leniu-java-export/SKILL.md +560 -0
- package/.codex/skills/leniu-java-logging/SKILL.md +832 -0
- package/.codex/skills/leniu-java-mq/SKILL.md +338 -0
- package/.codex/skills/leniu-java-mybatis/SKILL.md +640 -0
- package/.codex/skills/leniu-java-report-query-param/SKILL.md +291 -0
- package/.codex/skills/leniu-java-task/SKILL.md +367 -0
- package/.codex/skills/leniu-java-total-line/SKILL.md +195 -0
- package/.codex/skills/leniu-marketing-price-rule-customizer/SKILL.md +301 -0
- package/.codex/skills/leniu-marketing-recharge-rule-customizer/SKILL.md +285 -0
- package/.codex/skills/leniu-mealtime/SKILL.md +215 -0
- package/.codex/skills/leniu-redis-cache/SKILL.md +316 -0
- package/.codex/skills/leniu-security-guard/SKILL.md +520 -0
- package/.codex/skills/leniu-utils-toolkit/SKILL.md +378 -0
- package/.codex/skills/next/SKILL.md +137 -0
- package/.codex/skills/openspec-apply-change/SKILL.md +156 -0
- package/.codex/skills/openspec-archive-change/SKILL.md +114 -0
- package/.codex/skills/openspec-bulk-archive-change/SKILL.md +246 -0
- package/.codex/skills/openspec-continue-change/SKILL.md +118 -0
- package/.codex/skills/openspec-explore/SKILL.md +290 -0
- package/.codex/skills/openspec-ff-change/SKILL.md +101 -0
- package/.codex/skills/openspec-new-change/SKILL.md +74 -0
- package/.codex/skills/openspec-onboard/SKILL.md +529 -0
- package/.codex/skills/openspec-sync-specs/SKILL.md +138 -0
- package/.codex/skills/openspec-verify-change/SKILL.md +168 -0
- package/.codex/skills/performance-doctor/SKILL.md +627 -0
- package/.codex/skills/progress/SKILL.md +193 -0
- package/.codex/skills/project-navigator/SKILL.md +286 -0
- package/.codex/skills/redis-cache/SKILL.md +829 -0
- package/.codex/skills/scheduled-jobs/SKILL.md +633 -0
- package/.codex/skills/security-guard/SKILL.md +739 -0
- package/.codex/skills/sms-mail/SKILL.md +766 -0
- package/.codex/skills/social-login/SKILL.md +668 -0
- package/.codex/skills/start/SKILL.md +154 -0
- package/.codex/skills/store-pc/SKILL.md +491 -0
- package/.codex/skills/sync/SKILL.md +149 -0
- package/.codex/skills/task-tracker/SKILL.md +307 -0
- package/.codex/skills/tech-decision/SKILL.md +393 -0
- package/.codex/skills/tenant-management/SKILL.md +603 -0
- package/.codex/skills/test-development/SKILL.md +755 -0
- package/.codex/skills/ui-pc/SKILL.md +475 -0
- package/.codex/skills/update-status/SKILL.md +159 -0
- package/.codex/skills/utils-toolkit/SKILL.md +593 -0
- package/.codex/skills/websocket-sse/SKILL.md +716 -0
- package/.codex/skills/workflow-engine/SKILL.md +676 -0
- package/.cursor/agents/code-reviewer.md +139 -0
- package/.cursor/agents/project-manager.md +159 -0
- package/.cursor/commands/opsx-apply.md +152 -0
- package/.cursor/commands/opsx-archive.md +157 -0
- package/.cursor/commands/opsx-bulk-archive.md +242 -0
- package/.cursor/commands/opsx-continue.md +114 -0
- package/.cursor/commands/opsx-explore.md +174 -0
- package/.cursor/commands/opsx-ff.md +94 -0
- package/.cursor/commands/opsx-new.md +69 -0
- package/.cursor/commands/opsx-onboard.md +525 -0
- package/.cursor/commands/opsx-sync.md +134 -0
- package/.cursor/commands/opsx-verify.md +164 -0
- package/.cursor/mcp.json +22 -0
- package/.cursor/skills/add-skill/SKILL.md +352 -0
- package/.cursor/skills/api-development/SKILL.md +560 -0
- package/.cursor/skills/architecture-design/SKILL.md +756 -0
- package/.cursor/skills/backend-annotations/SKILL.md +674 -0
- package/.cursor/skills/banana-image/CHANGELOG.md +37 -0
- package/.cursor/skills/banana-image/README.md +146 -0
- package/.cursor/skills/banana-image/SKILL.md +164 -0
- package/.cursor/skills/banana-image/assets/logo.png +0 -0
- package/.cursor/skills/banana-image/references/advanced-usage.md +189 -0
- package/.cursor/skills/banana-image/scripts/apply_template.py +125 -0
- package/.cursor/skills/banana-image/scripts/banana_image_exec.ts +412 -0
- package/.cursor/skills/banana-image/scripts/batch_prep.py +82 -0
- package/.cursor/skills/banana-image/scripts/package-lock.json +1437 -0
- package/.cursor/skills/banana-image/scripts/package.json +18 -0
- package/.cursor/skills/banana-image/scripts/requirements.txt +10 -0
- package/.cursor/skills/banana-image/templates/poster.json +22 -0
- package/.cursor/skills/banana-image/templates/product.json +17 -0
- package/.cursor/skills/banana-image/templates/social.json +22 -0
- package/.cursor/skills/banana-image/templates/thumbnail.json +17 -0
- package/.cursor/skills/brainstorm/SKILL.md +648 -0
- package/.cursor/skills/bug-detective/SKILL.md +1206 -0
- package/.cursor/skills/code-patterns/SKILL.md +590 -0
- package/.cursor/skills/collaborating-with-codex/SKILL.md +174 -0
- package/.cursor/skills/collaborating-with-codex/scripts/codex_bridge.py +275 -0
- package/.cursor/skills/collaborating-with-gemini/SKILL.md +194 -0
- package/.cursor/skills/collaborating-with-gemini/scripts/gemini_bridge.py +275 -0
- package/.cursor/skills/crud-development/SKILL.md +649 -0
- package/.cursor/skills/data-permission/SKILL.md +599 -0
- package/.cursor/skills/database-ops/SKILL.md +407 -0
- package/.cursor/skills/error-handler/SKILL.md +371 -0
- package/.cursor/skills/file-oss-management/SKILL.md +863 -0
- package/.cursor/skills/git-workflow/SKILL.md +375 -0
- package/.cursor/skills/json-serialization/SKILL.md +357 -0
- package/.cursor/skills/leniu-api-development/SKILL.md +803 -0
- package/.cursor/skills/leniu-architecture-design/SKILL.md +598 -0
- package/.cursor/skills/leniu-backend-annotations/SKILL.md +664 -0
- package/.cursor/skills/leniu-code-patterns/SKILL.md +365 -0
- package/.cursor/skills/leniu-crud-development/SKILL.md +1110 -0
- package/.cursor/skills/leniu-data-permission/SKILL.md +256 -0
- package/.cursor/skills/leniu-database-ops/SKILL.md +426 -0
- package/.cursor/skills/leniu-error-handler/SKILL.md +462 -0
- package/.cursor/skills/leniu-java-amount-handling/SKILL.md +461 -0
- package/.cursor/skills/leniu-java-code-style/SKILL.md +510 -0
- package/.cursor/skills/leniu-java-concurrent/SKILL.md +400 -0
- package/.cursor/skills/leniu-java-entity/SKILL.md +751 -0
- package/.cursor/skills/leniu-java-export/SKILL.md +560 -0
- package/.cursor/skills/leniu-java-logging/SKILL.md +832 -0
- package/.cursor/skills/leniu-java-mq/SKILL.md +338 -0
- package/.cursor/skills/leniu-java-mybatis/SKILL.md +640 -0
- package/.cursor/skills/leniu-java-report-query-param/SKILL.md +291 -0
- package/.cursor/skills/leniu-java-task/SKILL.md +367 -0
- package/.cursor/skills/leniu-java-total-line/SKILL.md +195 -0
- package/.cursor/skills/leniu-marketing-price-rule-customizer/SKILL.md +301 -0
- package/.cursor/skills/leniu-marketing-recharge-rule-customizer/SKILL.md +285 -0
- package/.cursor/skills/leniu-mealtime/SKILL.md +215 -0
- package/.cursor/skills/leniu-redis-cache/SKILL.md +316 -0
- package/.cursor/skills/leniu-security-guard/SKILL.md +520 -0
- package/.cursor/skills/leniu-utils-toolkit/SKILL.md +380 -0
- package/.cursor/skills/openspec-apply-change/SKILL.md +156 -0
- package/.cursor/skills/openspec-archive-change/SKILL.md +114 -0
- package/.cursor/skills/openspec-bulk-archive-change/SKILL.md +246 -0
- package/.cursor/skills/openspec-continue-change/SKILL.md +118 -0
- package/.cursor/skills/openspec-explore/SKILL.md +290 -0
- package/.cursor/skills/openspec-ff-change/SKILL.md +101 -0
- package/.cursor/skills/openspec-new-change/SKILL.md +74 -0
- package/.cursor/skills/openspec-onboard/SKILL.md +529 -0
- package/.cursor/skills/openspec-sync-specs/SKILL.md +138 -0
- package/.cursor/skills/openspec-verify-change/SKILL.md +168 -0
- package/.cursor/skills/performance-doctor/SKILL.md +627 -0
- package/.cursor/skills/project-navigator/SKILL.md +305 -0
- package/.cursor/skills/redis-cache/SKILL.md +839 -0
- package/.cursor/skills/scheduled-jobs/SKILL.md +633 -0
- package/.cursor/skills/security-guard/SKILL.md +748 -0
- package/.cursor/skills/sms-mail/SKILL.md +766 -0
- package/.cursor/skills/social-login/SKILL.md +668 -0
- package/.cursor/skills/store-pc/SKILL.md +366 -0
- package/.cursor/skills/task-tracker/SKILL.md +307 -0
- package/.cursor/skills/tech-decision/SKILL.md +393 -0
- package/.cursor/skills/tenant-management/SKILL.md +603 -0
- package/.cursor/skills/test-development/SKILL.md +755 -0
- package/.cursor/skills/ui-pc/SKILL.md +438 -0
- package/.cursor/skills/utils-toolkit/SKILL.md +615 -0
- package/.cursor/skills/websocket-sse/SKILL.md +716 -0
- package/.cursor/skills/workflow-engine/SKILL.md +676 -0
- package/AGENTS.md +669 -0
- package/CLAUDE.md +205 -0
- package/README.md +205 -0
- package/bin/index.js +179 -0
- package/init.sh +178 -0
- package/package.json +27 -0
|
@@ -0,0 +1,832 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: leniu-java-logging
|
|
3
|
+
description: |
|
|
4
|
+
leniu-tengyun-core / leniu-yunshitang 项目日志规范。当编写日志代码时使用此 skill,包括日志框架使用、级别选择、异常日志规范和日志文件管理。
|
|
5
|
+
|
|
6
|
+
触发场景:
|
|
7
|
+
- 编写日志记录代码(@Slf4j、log.info/error/debug)
|
|
8
|
+
- 配置日志级别和输出格式
|
|
9
|
+
- 记录异常日志(含完整堆栈)
|
|
10
|
+
- 业务关键路径日志埋点
|
|
11
|
+
- 日志文件管理和保留策略
|
|
12
|
+
|
|
13
|
+
触发词:日志、@Slf4j、log.info、log.error、log.debug、log.warn、日志级别、日志格式、日志记录、logging、logback、leniu-yunshitang、leniu-tengyun-core、net.xnzn
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# leniu-tengyun-core / leniu-yunshitang 日志规范
|
|
17
|
+
|
|
18
|
+
## 项目定位
|
|
19
|
+
|
|
20
|
+
| **适用项目** | leniu-tengyun-core:`/Users/xujiajun/Developer/gongsi_proj/leniu-api/leniu-tengyun-core` |
|
|
21
|
+
|-------------|------------------------------------------------------------------------------------------|
|
|
22
|
+
| | leniu-yunshitang:`/Users/xujiajun/Developer/gongsi_proj/leniu-api/leniu-tengyun/leniu-yunshitang` |
|
|
23
|
+
|
|
24
|
+
## 日志框架配置
|
|
25
|
+
|
|
26
|
+
### 使用 SLF4J + Lombok
|
|
27
|
+
|
|
28
|
+
```java
|
|
29
|
+
import lombok.extern.slf4j.Slf4j;
|
|
30
|
+
|
|
31
|
+
@Slf4j
|
|
32
|
+
@Service
|
|
33
|
+
public class XxxService {
|
|
34
|
+
|
|
35
|
+
public void doSomething() {
|
|
36
|
+
log.info("开始处理");
|
|
37
|
+
log.debug("详细信息");
|
|
38
|
+
log.warn("警告信息");
|
|
39
|
+
log.error("错误信息");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 不要直接使用日志实现
|
|
45
|
+
|
|
46
|
+
```java
|
|
47
|
+
// ❌ 错误:直接使用 Log4j/Logback
|
|
48
|
+
import org.apache.log4j.Logger;
|
|
49
|
+
Logger logger = Logger.getLogger(XxxService.class);
|
|
50
|
+
|
|
51
|
+
// ✅ 正确:使用 SLF4J
|
|
52
|
+
import lombok.extern.slf4j.Slf4j;
|
|
53
|
+
@Slf4j
|
|
54
|
+
public class XxxService { }
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 日志配置文件
|
|
58
|
+
|
|
59
|
+
项目使用 Logback 日志框架,配置文件位于:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
core-starter/src/main/resources/logback-spring.xml
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```xml
|
|
66
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
67
|
+
<configuration>
|
|
68
|
+
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
|
69
|
+
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
|
|
70
|
+
<include resource="org/springframework/boot/logging/logback/file-appender.xml"/>
|
|
71
|
+
|
|
72
|
+
<springProfile name="!no_log_console">
|
|
73
|
+
<root level="INFO">
|
|
74
|
+
<appender-ref ref="CONSOLE"/>
|
|
75
|
+
</root>
|
|
76
|
+
</springProfile>
|
|
77
|
+
|
|
78
|
+
<springProfile name="!no_log_file">
|
|
79
|
+
<root level="INFO">
|
|
80
|
+
<appender-ref ref="FILE"/>
|
|
81
|
+
</root>
|
|
82
|
+
</springProfile>
|
|
83
|
+
</configuration>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Profile 控制
|
|
87
|
+
|
|
88
|
+
| Profile | 作用 |
|
|
89
|
+
|---------|------|
|
|
90
|
+
| `no_log_console` | 不输出到控制台 |
|
|
91
|
+
| `no_log_file` | 不输出到文件 |
|
|
92
|
+
|
|
93
|
+
## 日志级别
|
|
94
|
+
|
|
95
|
+
### ERROR - 错误日志
|
|
96
|
+
|
|
97
|
+
用于记录系统错误、异常情况,需要立即关注和处理。
|
|
98
|
+
|
|
99
|
+
```java
|
|
100
|
+
import cn.hutool.core.util.ObjectUtil;
|
|
101
|
+
import lombok.extern.slf4j.Slf4j;
|
|
102
|
+
|
|
103
|
+
@Slf4j
|
|
104
|
+
@Service
|
|
105
|
+
public class OrderService {
|
|
106
|
+
|
|
107
|
+
public void processOrder(Long orderId) {
|
|
108
|
+
try {
|
|
109
|
+
// 业务逻辑
|
|
110
|
+
doProcess(orderId);
|
|
111
|
+
} catch (Exception e) {
|
|
112
|
+
log.error("订单处理失败, orderId:{}", orderId, e);
|
|
113
|
+
throw new LeException("订单处理失败");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 业务异常
|
|
118
|
+
public void validateOrder(Order order) {
|
|
119
|
+
if (ObjectUtil.isNull(order)) {
|
|
120
|
+
log.error("订单不存在, orderId:{}", orderId);
|
|
121
|
+
throw new LeException("订单不存在");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 业务数据异常
|
|
126
|
+
public void checkGoods(List<String> missingNames) {
|
|
127
|
+
log.error("以下{}个货品在系统中不存在: {}", missingNames.size(), missingNames);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### WARN - 警告日志
|
|
133
|
+
|
|
134
|
+
用于记录非预期但可处理的情况,不影响系统运行但需要关注。
|
|
135
|
+
|
|
136
|
+
```java
|
|
137
|
+
import cn.hutool.core.util.ObjectUtil;
|
|
138
|
+
import cn.hutool.core.util.StrUtil;
|
|
139
|
+
import lombok.extern.slf4j.Slf4j;
|
|
140
|
+
|
|
141
|
+
@Slf4j
|
|
142
|
+
@Service
|
|
143
|
+
public class ConfigService {
|
|
144
|
+
|
|
145
|
+
// 数据不存在
|
|
146
|
+
public Config getConfig(String key) {
|
|
147
|
+
Config config = configMapper.selectById(key);
|
|
148
|
+
if (ObjectUtil.isNull(config)) {
|
|
149
|
+
log.warn("配置不存在, key:{}", key);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
return config;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 配置缺失
|
|
156
|
+
public String getConfigWithDefault(String key, String defaultValue) {
|
|
157
|
+
String value = getConfigValue(key);
|
|
158
|
+
if (StrUtil.isBlank(value)) {
|
|
159
|
+
log.warn("配置项缺失, key:{}, 使用默认值", key);
|
|
160
|
+
return defaultValue;
|
|
161
|
+
}
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### INFO - 信息日志
|
|
168
|
+
|
|
169
|
+
用于记录关键业务节点、重要操作,便于追踪业务流程。
|
|
170
|
+
|
|
171
|
+
```java
|
|
172
|
+
import lombok.extern.slf4j.Slf4j;
|
|
173
|
+
|
|
174
|
+
@Slf4j
|
|
175
|
+
@Service
|
|
176
|
+
public class OrderService {
|
|
177
|
+
|
|
178
|
+
@Transactional(rollbackFor = Exception.class)
|
|
179
|
+
public Long createOrder(OrderParam param) {
|
|
180
|
+
log.info("【订单】开始创建订单, userId:{}, productId:{}",
|
|
181
|
+
param.getUserId(), param.getProductId());
|
|
182
|
+
|
|
183
|
+
// 业务逻辑
|
|
184
|
+
Order order = buildOrder(param);
|
|
185
|
+
orderMapper.insert(order);
|
|
186
|
+
|
|
187
|
+
log.info("【订单】订单创建成功, orderId:{}", order.getId());
|
|
188
|
+
return order.getId();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
public void payOrder(Long orderId, Long amount) {
|
|
192
|
+
log.info("【支付】开始支付, orderId:{}, amount:{}", orderId, amount);
|
|
193
|
+
|
|
194
|
+
// 支付逻辑
|
|
195
|
+
PaymentResult result = paymentService.pay(orderId, amount);
|
|
196
|
+
|
|
197
|
+
log.info("【支付】支付成功, orderId:{}, transactionId:{}",
|
|
198
|
+
orderId, result.getTransactionId());
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### DEBUG - 调试日志
|
|
204
|
+
|
|
205
|
+
用于开发调试,记录详细的执行过程和数据。生产环境不输出。
|
|
206
|
+
|
|
207
|
+
```java
|
|
208
|
+
import lombok.extern.slf4j.Slf4j;
|
|
209
|
+
|
|
210
|
+
@Slf4j
|
|
211
|
+
@Service
|
|
212
|
+
public class OrderService {
|
|
213
|
+
|
|
214
|
+
public List<OrderVO> queryList(OrderQueryParam param) {
|
|
215
|
+
log.debug("查询参数: {}", param);
|
|
216
|
+
|
|
217
|
+
// 执行查询
|
|
218
|
+
List<OrderEntity> entities = orderMapper.selectList(buildWrapper(param));
|
|
219
|
+
|
|
220
|
+
log.debug("查询结果数量: {}", entities.size());
|
|
221
|
+
log.debug("查询结果: {}", entities);
|
|
222
|
+
|
|
223
|
+
return BeanUtil.copyToList(entities, OrderVO.class);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## 日志输出格式
|
|
229
|
+
|
|
230
|
+
### 使用占位符
|
|
231
|
+
|
|
232
|
+
```java
|
|
233
|
+
import lombok.extern.slf4j.Slf4j;
|
|
234
|
+
|
|
235
|
+
@Slf4j
|
|
236
|
+
@Service
|
|
237
|
+
public class UserService {
|
|
238
|
+
|
|
239
|
+
// ✅ 正确:使用占位符
|
|
240
|
+
public void login(String username, String password) {
|
|
241
|
+
log.info("用户登录, userId:{}, userName:{}", userId, userName);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// ❌ 错误:字符串拼接
|
|
245
|
+
public void loginWrong(String username, String password) {
|
|
246
|
+
log.info("用户登录, userId:" + userId + ", userName:" + userName);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### 条件输出
|
|
252
|
+
|
|
253
|
+
```java
|
|
254
|
+
import lombok.extern.slf4j.Slf4j;
|
|
255
|
+
|
|
256
|
+
@Slf4j
|
|
257
|
+
@Service
|
|
258
|
+
public class QueryService {
|
|
259
|
+
|
|
260
|
+
// ✅ 对于 debug/trace 级别,使用条件输出
|
|
261
|
+
public void queryWithDebug(Data param) {
|
|
262
|
+
if (log.isDebugEnabled()) {
|
|
263
|
+
log.debug("详细数据: {}", expensiveOperation());
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ✅ 或使用 Lambda 形式(推荐)
|
|
268
|
+
public void queryWithLambda(Data param) {
|
|
269
|
+
log.debug("详细数据: {}", () -> expensiveOperation());
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### 模块标识
|
|
275
|
+
|
|
276
|
+
使用 `【模块名】` 标识,便于日志检索:
|
|
277
|
+
|
|
278
|
+
```java
|
|
279
|
+
import lombok.extern.slf4j.Slf4j;
|
|
280
|
+
|
|
281
|
+
@Slf4j
|
|
282
|
+
@Service
|
|
283
|
+
public class OrderService {
|
|
284
|
+
|
|
285
|
+
public void createOrder(OrderParam param) {
|
|
286
|
+
log.info("【订单】开始创建订单, userId:{}", param.getUserId());
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
@Slf4j
|
|
291
|
+
@Service
|
|
292
|
+
public class PaymentService {
|
|
293
|
+
|
|
294
|
+
public void pay(Long orderId) {
|
|
295
|
+
log.info("【支付】开始支付, orderId:{}", orderId);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
@Slf4j
|
|
300
|
+
@Service
|
|
301
|
+
public class InventoryService {
|
|
302
|
+
|
|
303
|
+
public void reduceStock(Long productId, Integer quantity) {
|
|
304
|
+
log.info("【库存】扣减库存, productId:{}, quantity:{}", productId, quantity);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## 异常日志
|
|
310
|
+
|
|
311
|
+
### 记录异常堆栈
|
|
312
|
+
|
|
313
|
+
```java
|
|
314
|
+
import lombok.extern.slf4j.Slf4j;
|
|
315
|
+
|
|
316
|
+
@Slf4j
|
|
317
|
+
@Service
|
|
318
|
+
public class OrderService {
|
|
319
|
+
|
|
320
|
+
public void processOrder(Long orderId) {
|
|
321
|
+
try {
|
|
322
|
+
doProcess(orderId);
|
|
323
|
+
} catch (Exception e) {
|
|
324
|
+
// ✅ 正确:异常作为最后一个参数
|
|
325
|
+
log.error("订单处理失败, orderId:{}", orderId, e);
|
|
326
|
+
throw new LeException("订单处理失败");
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
```java
|
|
333
|
+
// ❌ 错误:只记录异常消息,丢失堆栈信息
|
|
334
|
+
try {
|
|
335
|
+
doSomething();
|
|
336
|
+
} catch (Exception e) {
|
|
337
|
+
log.error("处理失败:{}", e.getMessage());
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### 记录案发现场
|
|
342
|
+
|
|
343
|
+
```java
|
|
344
|
+
import lombok.extern.slf4j.Slf4j;
|
|
345
|
+
|
|
346
|
+
@Slf4j
|
|
347
|
+
@Service
|
|
348
|
+
public class OrderService {
|
|
349
|
+
|
|
350
|
+
public void updateOrderStatus(Long orderId, Integer status) {
|
|
351
|
+
try {
|
|
352
|
+
// 业务逻辑
|
|
353
|
+
updateStatus(orderId, status);
|
|
354
|
+
} catch (Exception e) {
|
|
355
|
+
// ✅ 记录关键参数和上下文
|
|
356
|
+
log.error("订单状态更新失败, orderId:{}, oldStatus:{}, newStatus:{}",
|
|
357
|
+
orderId, oldStatus, status, e);
|
|
358
|
+
throw new LeException("订单状态更新失败");
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## 敏感信息处理
|
|
365
|
+
|
|
366
|
+
### 不要记录敏感信息
|
|
367
|
+
|
|
368
|
+
```java
|
|
369
|
+
import lombok.extern.slf4j.Slf4j;
|
|
370
|
+
|
|
371
|
+
@Slf4j
|
|
372
|
+
@Service
|
|
373
|
+
public class UserService {
|
|
374
|
+
|
|
375
|
+
// ❌ 错误:记录密码
|
|
376
|
+
public void login(String username, String password) {
|
|
377
|
+
log.info("用户登录, username:{}, password:{}", username, password);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// ✅ 正确:不记录密码
|
|
381
|
+
public void login(String username, String password) {
|
|
382
|
+
log.info("用户登录, username:{}", username);
|
|
383
|
+
// 验证密码
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// ❌ 错误:记录完整手机号
|
|
387
|
+
public void sendSms(String mobile, String code) {
|
|
388
|
+
log.info("发送验证码, mobile:{}, code:{}", mobile, code);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// ✅ 正确:脱敏处理
|
|
392
|
+
public void sendSms(String mobile, String code) {
|
|
393
|
+
log.info("发送验证码, mobile:{}", maskMobile(mobile));
|
|
394
|
+
// 发送短信
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### 脱敏工具方法
|
|
400
|
+
|
|
401
|
+
```java
|
|
402
|
+
public class DataMaskUtil {
|
|
403
|
+
|
|
404
|
+
// 手机号脱敏:138****1234
|
|
405
|
+
public static String maskMobile(String mobile) {
|
|
406
|
+
if (StrUtil.isBlank(mobile) || mobile.length() != 11) {
|
|
407
|
+
return mobile;
|
|
408
|
+
}
|
|
409
|
+
return mobile.substring(0, 3) + "****" + mobile.substring(7);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// 身份证脱敏:1234**********5678
|
|
413
|
+
public static String maskIdCard(String idCard) {
|
|
414
|
+
if (StrUtil.isBlank(idCard) || idCard.length() < 8) {
|
|
415
|
+
return idCard;
|
|
416
|
+
}
|
|
417
|
+
return idCard.substring(0, 4) + "**********" + idCard.substring(idCard.length() - 4);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// 银行卡脱敏:6222************8888
|
|
421
|
+
public static String maskBankCard(String bankCard) {
|
|
422
|
+
if (StrUtil.isBlank(bankCard) || bankCard.length() < 8) {
|
|
423
|
+
return bankCard;
|
|
424
|
+
}
|
|
425
|
+
return bankCard.substring(0, 4) + "************" + bankCard.substring(bankCard.length() - 4);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
## 日志内容规范
|
|
431
|
+
|
|
432
|
+
### 1. 关键业务操作
|
|
433
|
+
|
|
434
|
+
```java
|
|
435
|
+
import lombok.extern.slf4j.Slf4j;
|
|
436
|
+
|
|
437
|
+
@Slf4j
|
|
438
|
+
@Service
|
|
439
|
+
public class OrderService {
|
|
440
|
+
|
|
441
|
+
@Transactional(rollbackFor = Exception.class)
|
|
442
|
+
public Long createOrder(OrderParam param) {
|
|
443
|
+
log.info("【订单】开始创建订单, userId:{}, productId:{}",
|
|
444
|
+
param.getUserId(), param.getProductId());
|
|
445
|
+
|
|
446
|
+
// 业务逻辑
|
|
447
|
+
Order order = buildOrder(param);
|
|
448
|
+
orderMapper.insert(order);
|
|
449
|
+
|
|
450
|
+
log.info("【订单】订单创建成功, orderId:{}", order.getId());
|
|
451
|
+
return order.getId();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
### 2. 外部调用
|
|
457
|
+
|
|
458
|
+
```java
|
|
459
|
+
import lombok.extern.slf4j.Slf4j;
|
|
460
|
+
|
|
461
|
+
@Slf4j
|
|
462
|
+
@Service
|
|
463
|
+
public class RemoteUserService {
|
|
464
|
+
|
|
465
|
+
public UserDTO getUserFromRemote(Long userId) {
|
|
466
|
+
log.info("【远程调用】开始调用用户服务, userId:{}", userId);
|
|
467
|
+
|
|
468
|
+
try {
|
|
469
|
+
UserDTO user = remoteUserService.getUser(userId);
|
|
470
|
+
log.info("【远程调用】用户服务调用成功, userId:{}", userId);
|
|
471
|
+
return user;
|
|
472
|
+
} catch (Exception e) {
|
|
473
|
+
log.error("【远程调用】用户服务调用失败, userId:{}", userId, e);
|
|
474
|
+
throw new LeException("用户信息获取失败");
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### 3. 定时任务
|
|
481
|
+
|
|
482
|
+
```java
|
|
483
|
+
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
484
|
+
import lombok.extern.slf4j.Slf4j;
|
|
485
|
+
|
|
486
|
+
@Slf4j
|
|
487
|
+
@Component
|
|
488
|
+
public class DataSyncJob {
|
|
489
|
+
|
|
490
|
+
@XxlJob("syncDataJob")
|
|
491
|
+
public void syncData() {
|
|
492
|
+
log.info("【定时任务】开始同步数据");
|
|
493
|
+
|
|
494
|
+
try {
|
|
495
|
+
int count = doSync();
|
|
496
|
+
log.info("【定时任务】数据同步完成, 同步数量:{}", count);
|
|
497
|
+
} catch (Exception e) {
|
|
498
|
+
log.error("【定时任务】数据同步失败", e);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### 4. 消息队列
|
|
505
|
+
|
|
506
|
+
```java
|
|
507
|
+
import lombok.extern.slf4j.Slf4j;
|
|
508
|
+
import net.xnzn.framework.mq.MQListener;
|
|
509
|
+
import net.xnzn.framework.mq.MQMessageListener;
|
|
510
|
+
|
|
511
|
+
// ✅ 正确:leniu 项目 MQ 消费者用 @MQMessageListener + implements MQListener
|
|
512
|
+
@Slf4j
|
|
513
|
+
@MQMessageListener(group = "order-order-v3-xxx", topic = "order", tag = "order-v3-xxx")
|
|
514
|
+
public class OrderMqListenerXxx implements MQListener<MqPayload<String>> {
|
|
515
|
+
|
|
516
|
+
@Override
|
|
517
|
+
public void onMessage(MqPayload<String> payload) {
|
|
518
|
+
log.info("[xxx事件]MQ消费:开始");
|
|
519
|
+
// 委托给 Handler 处理
|
|
520
|
+
orderMqHandler.handleMessage(payload, OrderXxxPO.class, OrderMqHandler::handleXxx);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Handler 中的日志规范
|
|
525
|
+
public void handleXxx(OrderXxxPO payload) {
|
|
526
|
+
try {
|
|
527
|
+
log.info("[xxx事件]MQ消费:开始");
|
|
528
|
+
processXxx(payload);
|
|
529
|
+
log.info("[xxx事件]MQ消费:消息消费完成");
|
|
530
|
+
} catch (Exception e) {
|
|
531
|
+
log.error("[xxx事件]MQ消费:处理异常", e);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
## 日志性能优化
|
|
537
|
+
|
|
538
|
+
### 1. 避免大对象序列化
|
|
539
|
+
|
|
540
|
+
```java
|
|
541
|
+
import lombok.extern.slf4j.Slf4j;
|
|
542
|
+
|
|
543
|
+
@Slf4j
|
|
544
|
+
@Service
|
|
545
|
+
public class QueryService {
|
|
546
|
+
|
|
547
|
+
// ❌ 避免:序列化大对象
|
|
548
|
+
public List<Order> queryOrders() {
|
|
549
|
+
List<Order> orders = orderMapper.selectList(null);
|
|
550
|
+
log.info("查询结果: {}", BeanUtil.beanToString(orders)); // 可能产生大量日志
|
|
551
|
+
return orders;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// ✅ 推荐:只记录关键信息
|
|
555
|
+
public List<Order> queryOrders() {
|
|
556
|
+
List<Order> orders = orderMapper.selectList(null);
|
|
557
|
+
log.info("查询结果数量: {}", orders.size());
|
|
558
|
+
return orders;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
### 2. 使用条件判断
|
|
564
|
+
|
|
565
|
+
```java
|
|
566
|
+
import lombok.extern.slf4j.Slf4j;
|
|
567
|
+
|
|
568
|
+
@Slf4j
|
|
569
|
+
@Service
|
|
570
|
+
public class DebugService {
|
|
571
|
+
|
|
572
|
+
// ✅ 对于复杂计算,使用条件判断
|
|
573
|
+
public void processComplexData(Data data) {
|
|
574
|
+
if (log.isDebugEnabled()) {
|
|
575
|
+
log.debug("详细数据: {}", buildComplexString(data));
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
### 3. 避免循环中打印日志
|
|
582
|
+
|
|
583
|
+
```java
|
|
584
|
+
import lombok.extern.slf4j.Slf4j;
|
|
585
|
+
|
|
586
|
+
@Slf4j
|
|
587
|
+
@Service
|
|
588
|
+
public class BatchOrderService {
|
|
589
|
+
|
|
590
|
+
// ❌ 避免:循环中打印日志
|
|
591
|
+
public void batchProcess(List<Order> orders) {
|
|
592
|
+
for (Order order : orders) {
|
|
593
|
+
log.info("处理订单, orderId:{}", order.getId()); // 可能产生大量日志
|
|
594
|
+
process(order);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// ✅ 推荐:批量处理后打印
|
|
599
|
+
public void batchProcess(List<Order> orders) {
|
|
600
|
+
log.info("开始处理订单, 数量:{}", orders.size());
|
|
601
|
+
|
|
602
|
+
int successCount = 0;
|
|
603
|
+
int failCount = 0;
|
|
604
|
+
for (Order order : orders) {
|
|
605
|
+
try {
|
|
606
|
+
process(order);
|
|
607
|
+
successCount++;
|
|
608
|
+
} catch (Exception e) {
|
|
609
|
+
log.error("订单处理失败, orderId:{}", order.getId(), e);
|
|
610
|
+
failCount++;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
log.info("订单处理完成, 成功:{}, 失败:{}", successCount, failCount);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
## 日志文件管理
|
|
620
|
+
|
|
621
|
+
### 日志保留时间
|
|
622
|
+
|
|
623
|
+
- 所有日志文件至少保存 **15天**
|
|
624
|
+
- 重要业务日志建议保存 **30天** 或更长
|
|
625
|
+
|
|
626
|
+
### 日志分类
|
|
627
|
+
|
|
628
|
+
```properties
|
|
629
|
+
# application.properties
|
|
630
|
+
# 按模块分类日志
|
|
631
|
+
logging.level.net.xnzn.core.order=INFO
|
|
632
|
+
logging.level.net.xnzn.core.payment=INFO
|
|
633
|
+
logging.level.net.xnzn.core.inventory=INFO
|
|
634
|
+
|
|
635
|
+
# 按功能分类日志
|
|
636
|
+
logging.file.name=logs/application.log
|
|
637
|
+
logging.file.error.name=logs/error.log
|
|
638
|
+
logging.file.business.name=logs/business.log
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
## 日志级别配置
|
|
642
|
+
|
|
643
|
+
### application.yml 配置
|
|
644
|
+
|
|
645
|
+
```yaml
|
|
646
|
+
logging:
|
|
647
|
+
level:
|
|
648
|
+
# 项目日志级别
|
|
649
|
+
net.xnzn.core.order: INFO
|
|
650
|
+
net.xnzn.core.payment: INFO
|
|
651
|
+
net.xnzn.core.inventory: INFO
|
|
652
|
+
|
|
653
|
+
# 框架日志级别
|
|
654
|
+
com.baomidou.mybatisplus: INFO
|
|
655
|
+
org.springframework: WARN
|
|
656
|
+
org.apache.ibatis: WARN
|
|
657
|
+
|
|
658
|
+
# 日志文件配置
|
|
659
|
+
file:
|
|
660
|
+
name: logs/application.log
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
### Profile 环境配置
|
|
664
|
+
|
|
665
|
+
```yaml
|
|
666
|
+
spring:
|
|
667
|
+
profiles:
|
|
668
|
+
active: dev
|
|
669
|
+
|
|
670
|
+
---
|
|
671
|
+
# 开发环境
|
|
672
|
+
spring:
|
|
673
|
+
profiles: dev
|
|
674
|
+
|
|
675
|
+
logging:
|
|
676
|
+
level:
|
|
677
|
+
net.xnzn.core: DEBUG
|
|
678
|
+
|
|
679
|
+
---
|
|
680
|
+
# 生产环境
|
|
681
|
+
spring:
|
|
682
|
+
profiles: prod
|
|
683
|
+
|
|
684
|
+
logging:
|
|
685
|
+
level:
|
|
686
|
+
net.xnzn.core: INFO
|
|
687
|
+
# 生产环境不输出到控制台
|
|
688
|
+
profiles:
|
|
689
|
+
include: no_log_console
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
## 常见场景
|
|
693
|
+
|
|
694
|
+
### 场景1:Controller 层
|
|
695
|
+
|
|
696
|
+
```java
|
|
697
|
+
import lombok.extern.slf4j.Slf4j;
|
|
698
|
+
|
|
699
|
+
@Slf4j
|
|
700
|
+
@RequiresAuthentication
|
|
701
|
+
@RestController
|
|
702
|
+
@RequestMapping("/api/order")
|
|
703
|
+
@Api(value = "订单管理", tags = "订单管理")
|
|
704
|
+
public class OrderController {
|
|
705
|
+
|
|
706
|
+
@Autowired
|
|
707
|
+
private OrderService orderService;
|
|
708
|
+
|
|
709
|
+
@ApiOperation(value = "创建订单")
|
|
710
|
+
@PostMapping("/create")
|
|
711
|
+
public Long create(@Valid @RequestBody LeRequest<OrderParam> request) {
|
|
712
|
+
OrderParam param = request.getContent();
|
|
713
|
+
log.info("【订单】创建订单请求, userId:{}, productId:{}",
|
|
714
|
+
param.getUserId(), param.getProductId());
|
|
715
|
+
|
|
716
|
+
Long orderId = orderService.create(param);
|
|
717
|
+
|
|
718
|
+
log.info("【订单】订单创建成功, orderId:{}", orderId);
|
|
719
|
+
return orderId;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
### 场景2:Service 层
|
|
725
|
+
|
|
726
|
+
```java
|
|
727
|
+
import lombok.extern.slf4j.Slf4j;
|
|
728
|
+
import org.springframework.transaction.annotation.Transactional;
|
|
729
|
+
|
|
730
|
+
@Slf4j
|
|
731
|
+
@Service
|
|
732
|
+
public class OrderService {
|
|
733
|
+
|
|
734
|
+
@Autowired
|
|
735
|
+
private OrderMapper orderMapper;
|
|
736
|
+
|
|
737
|
+
@Transactional(rollbackFor = Exception.class)
|
|
738
|
+
public Long create(OrderParam param) {
|
|
739
|
+
log.info("【订单】开始创建订单, param:{}", param);
|
|
740
|
+
|
|
741
|
+
try {
|
|
742
|
+
// 业务逻辑
|
|
743
|
+
Order order = buildOrder(param);
|
|
744
|
+
orderMapper.insert(order);
|
|
745
|
+
|
|
746
|
+
log.info("【订单】订单创建成功, orderId:{}", order.getId());
|
|
747
|
+
return order.getId();
|
|
748
|
+
} catch (Exception e) {
|
|
749
|
+
log.error("【订单】订单创建失败, param:{}", param, e);
|
|
750
|
+
throw new LeException("订单创建失败");
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
### 场景3:分页查询
|
|
757
|
+
|
|
758
|
+
```java
|
|
759
|
+
import lombok.extern.slf4j.Slf4j;
|
|
760
|
+
import com.github.pagehelper.Page;
|
|
761
|
+
import com.github.pagehelper.PageHelper;
|
|
762
|
+
|
|
763
|
+
@Slf4j
|
|
764
|
+
@Service
|
|
765
|
+
public class OrderService {
|
|
766
|
+
|
|
767
|
+
public Page<OrderVO> pageList(OrderQueryParam param) {
|
|
768
|
+
log.info("【订单】分页查询订单, pageNum:{}, pageSize:{}, keyword:{}",
|
|
769
|
+
param.getPage().getPageNum(),
|
|
770
|
+
param.getPage().getPageSize(),
|
|
771
|
+
param.getKeyword());
|
|
772
|
+
|
|
773
|
+
// 开启分页
|
|
774
|
+
PageMethod.startPage(param.getPage().getPageNum(), param.getPage().getPageSize());
|
|
775
|
+
|
|
776
|
+
List<OrderEntity> records = orderMapper.selectList(buildWrapper(param));
|
|
777
|
+
Page<OrderVO> result = new Page<>(BeanUtil.copyToList(records, OrderVO.class));
|
|
778
|
+
|
|
779
|
+
log.info("【订单】分页查询完成, total:{}", result.getTotal());
|
|
780
|
+
return result;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
```
|
|
784
|
+
|
|
785
|
+
## 最佳实践
|
|
786
|
+
|
|
787
|
+
### 1. 日志要有意义
|
|
788
|
+
|
|
789
|
+
```java
|
|
790
|
+
// ❌ 无意义的日志
|
|
791
|
+
log.info("进入方法");
|
|
792
|
+
log.info("退出方法");
|
|
793
|
+
|
|
794
|
+
// ✅ 有意义的日志
|
|
795
|
+
log.info("【订单】开始创建订单, userId:{}", userId);
|
|
796
|
+
log.info("【订单】订单创建成功, orderId:{}", orderId);
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
### 2. 日志要完整
|
|
800
|
+
|
|
801
|
+
```java
|
|
802
|
+
// ✅ 记录完整的业务流程
|
|
803
|
+
log.info("【支付】开始支付, orderId:{}, amount:{}", orderId, amount);
|
|
804
|
+
// 调用支付接口
|
|
805
|
+
log.info("【支付】支付接口调用成功, orderId:{}, transactionId:{}", orderId, transactionId);
|
|
806
|
+
// 更新订单状态
|
|
807
|
+
log.info("【支付】订单状态更新成功, orderId:{}", orderId);
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
### 3. 日志要准确
|
|
811
|
+
|
|
812
|
+
```java
|
|
813
|
+
// ✅ 准确描述操作结果
|
|
814
|
+
log.info("【库存】扣减库存成功, productId:{}, quantity:{}", productId, quantity);
|
|
815
|
+
log.warn("【库存】库存不足, productId:{}, available:{}, required:{}",
|
|
816
|
+
productId, available, required);
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
### 4. 使用中文
|
|
820
|
+
|
|
821
|
+
```java
|
|
822
|
+
// ❌ 英文日志
|
|
823
|
+
log.info("Order created successfully, orderId:{}", orderId);
|
|
824
|
+
|
|
825
|
+
// ✅ 中文日志
|
|
826
|
+
log.info("【订单】订单创建成功, orderId:{}", orderId);
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
## 参考文档
|
|
830
|
+
|
|
831
|
+
- leniu-tengyun-core 源码:`/Users/xujiajun/Developer/gongsi_proj/leniu-api/leniu-tengyun-core`
|
|
832
|
+
- leniu-yunshitang 源码:`/Users/xujiajun/Developer/gongsi_proj/leniu-api/leniu-tengyun/leniu-yunshitang`
|