@renxqoo/renx-code 0.0.8 → 0.0.10

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.
Files changed (286) hide show
  1. package/README.md +114 -40
  2. package/bin/renx.cjs +79 -42
  3. package/bin/renx.exe +0 -0
  4. package/package.json +10 -28
  5. package/src/App.tsx +0 -297
  6. package/src/agent/runtime/event-format.ts +0 -258
  7. package/src/agent/runtime/model-types.ts +0 -13
  8. package/src/agent/runtime/runtime.context-usage.test.ts +0 -192
  9. package/src/agent/runtime/runtime.error-handling.test.ts +0 -235
  10. package/src/agent/runtime/runtime.simple.test.ts +0 -16
  11. package/src/agent/runtime/runtime.test.ts +0 -296
  12. package/src/agent/runtime/runtime.ts +0 -875
  13. package/src/agent/runtime/runtime.usage-forwarding.test.ts +0 -228
  14. package/src/agent/runtime/source-modules.test.ts +0 -38
  15. package/src/agent/runtime/source-modules.ts +0 -370
  16. package/src/agent/runtime/tool-call-buffer.test.ts +0 -65
  17. package/src/agent/runtime/tool-call-buffer.ts +0 -60
  18. package/src/agent/runtime/tool-confirmation.test.ts +0 -56
  19. package/src/agent/runtime/tool-confirmation.ts +0 -15
  20. package/src/agent/runtime/types.ts +0 -99
  21. package/src/commands/slash-commands.test.ts +0 -216
  22. package/src/commands/slash-commands.ts +0 -64
  23. package/src/components/chat/assistant-reply.test.tsx +0 -47
  24. package/src/components/chat/assistant-reply.tsx +0 -136
  25. package/src/components/chat/assistant-segment.test.ts +0 -99
  26. package/src/components/chat/assistant-segment.tsx +0 -125
  27. package/src/components/chat/assistant-tool-group.tsx +0 -900
  28. package/src/components/chat/code-block.test.tsx +0 -206
  29. package/src/components/chat/code-block.tsx +0 -313
  30. package/src/components/chat/prompt-card.tsx +0 -81
  31. package/src/components/chat/segment-groups.test.ts +0 -52
  32. package/src/components/chat/segment-groups.ts +0 -106
  33. package/src/components/chat/turn-item.tsx +0 -39
  34. package/src/components/conversation-panel.tsx +0 -43
  35. package/src/components/file-mention-menu.tsx +0 -77
  36. package/src/components/file-picker-dialog.tsx +0 -206
  37. package/src/components/footer-hints.tsx +0 -75
  38. package/src/components/model-picker-dialog.tsx +0 -248
  39. package/src/components/prompt.tsx +0 -233
  40. package/src/components/slash-command-menu.tsx +0 -65
  41. package/src/components/tool-confirm-dialog-content.test.ts +0 -103
  42. package/src/components/tool-confirm-dialog-content.ts +0 -186
  43. package/src/components/tool-confirm-dialog.tsx +0 -187
  44. package/src/components/tool-display-config.ts +0 -119
  45. package/src/context-usage-regressions.test.ts +0 -26
  46. package/src/files/attachment-capabilities.test.ts +0 -30
  47. package/src/files/attachment-capabilities.ts +0 -50
  48. package/src/files/attachment-content.ts +0 -153
  49. package/src/files/file-mention-query.test.ts +0 -34
  50. package/src/files/file-mention-query.ts +0 -32
  51. package/src/files/prompt-display.ts +0 -13
  52. package/src/files/types.ts +0 -5
  53. package/src/files/workspace-files.ts +0 -61
  54. package/src/hooks/agent-event-handlers.test.ts +0 -207
  55. package/src/hooks/agent-event-handlers.ts +0 -196
  56. package/src/hooks/chat-local-replies.fixed.test.ts +0 -119
  57. package/src/hooks/chat-local-replies.test.ts +0 -153
  58. package/src/hooks/chat-local-replies.ts +0 -63
  59. package/src/hooks/turn-updater.test.ts +0 -70
  60. package/src/hooks/turn-updater.ts +0 -166
  61. package/src/hooks/use-agent-chat.context.test.ts +0 -10
  62. package/src/hooks/use-agent-chat.status.test.ts +0 -14
  63. package/src/hooks/use-agent-chat.test.ts +0 -80
  64. package/src/hooks/use-agent-chat.ts +0 -621
  65. package/src/hooks/use-file-mention-menu.ts +0 -196
  66. package/src/hooks/use-file-picker.ts +0 -185
  67. package/src/hooks/use-model-picker.ts +0 -196
  68. package/src/hooks/use-slash-command-menu.ts +0 -154
  69. package/src/index.tsx +0 -55
  70. package/src/runtime/clipboard.test.ts +0 -43
  71. package/src/runtime/clipboard.ts +0 -89
  72. package/src/runtime/exit.test.ts +0 -177
  73. package/src/runtime/exit.ts +0 -98
  74. package/src/runtime/runtime-support.test.ts +0 -31
  75. package/src/runtime/terminal-theme.test.ts +0 -55
  76. package/src/runtime/terminal-theme.ts +0 -196
  77. package/src/types/chat.ts +0 -32
  78. package/src/types/message-content.ts +0 -48
  79. package/src/ui/open-code-theme.ts +0 -176
  80. package/src/ui/opencode-markdown.ts +0 -211
  81. package/src/ui/theme.simple.test.ts +0 -52
  82. package/src/ui/theme.test.ts +0 -151
  83. package/src/ui/theme.ts +0 -152
  84. package/src/utils/time.test.ts +0 -144
  85. package/src/utils/time.ts +0 -7
  86. package/tsconfig.json +0 -30
  87. package/vendor/agent-root/src/agent/ENTERPRISE_ACCEPTANCE_CHECKLIST.md +0 -95
  88. package/vendor/agent-root/src/agent/ENTERPRISE_REALTIME.html +0 -1345
  89. package/vendor/agent-root/src/agent/ENTERPRISE_REALTIME.md +0 -1353
  90. package/vendor/agent-root/src/agent/ERROR_CONTRACT.md +0 -60
  91. package/vendor/agent-root/src/agent/TEST_COVERAGE_ANALYSIS.md +0 -278
  92. package/vendor/agent-root/src/agent/__test__/error-contract.test.ts +0 -72
  93. package/vendor/agent-root/src/agent/__test__/types.test.ts +0 -137
  94. package/vendor/agent-root/src/agent/agent/__test__/abort-runtime.test.ts +0 -83
  95. package/vendor/agent-root/src/agent/agent/__test__/callback-safety.test.ts +0 -34
  96. package/vendor/agent-root/src/agent/agent/__test__/compaction.test.ts +0 -323
  97. package/vendor/agent-root/src/agent/agent/__test__/concurrency.test.ts +0 -290
  98. package/vendor/agent-root/src/agent/agent/__test__/error-normalizer.test.ts +0 -377
  99. package/vendor/agent-root/src/agent/agent/__test__/error.test.ts +0 -212
  100. package/vendor/agent-root/src/agent/agent/__test__/fault-injection.test.ts +0 -295
  101. package/vendor/agent-root/src/agent/agent/__test__/index.test.ts +0 -3607
  102. package/vendor/agent-root/src/agent/agent/__test__/logger.test.ts +0 -35
  103. package/vendor/agent-root/src/agent/agent/__test__/message-utils.test.ts +0 -517
  104. package/vendor/agent-root/src/agent/agent/__test__/telemetry.test.ts +0 -97
  105. package/vendor/agent-root/src/agent/agent/__test__/timeout-budget.test.ts +0 -479
  106. package/vendor/agent-root/src/agent/agent/__test__/tool-call-merge.test.ts +0 -80
  107. package/vendor/agent-root/src/agent/agent/__test__/tool-execution-ledger.test.ts +0 -76
  108. package/vendor/agent-root/src/agent/agent/__test__/write-buffer.test.ts +0 -173
  109. package/vendor/agent-root/src/agent/agent/__test__/write-file-session.test.ts +0 -109
  110. package/vendor/agent-root/src/agent/agent/abort-runtime.ts +0 -71
  111. package/vendor/agent-root/src/agent/agent/callback-safety.ts +0 -33
  112. package/vendor/agent-root/src/agent/agent/compaction.ts +0 -291
  113. package/vendor/agent-root/src/agent/agent/concurrency.ts +0 -103
  114. package/vendor/agent-root/src/agent/agent/error-normalizer.ts +0 -190
  115. package/vendor/agent-root/src/agent/agent/error.ts +0 -198
  116. package/vendor/agent-root/src/agent/agent/index.ts +0 -1772
  117. package/vendor/agent-root/src/agent/agent/logger.ts +0 -65
  118. package/vendor/agent-root/src/agent/agent/message-utils.ts +0 -101
  119. package/vendor/agent-root/src/agent/agent/stream-events.ts +0 -61
  120. package/vendor/agent-root/src/agent/agent/telemetry.ts +0 -123
  121. package/vendor/agent-root/src/agent/agent/timeout-budget.ts +0 -227
  122. package/vendor/agent-root/src/agent/agent/tool-call-merge.ts +0 -111
  123. package/vendor/agent-root/src/agent/agent/tool-execution-ledger.ts +0 -164
  124. package/vendor/agent-root/src/agent/agent/write-buffer.ts +0 -188
  125. package/vendor/agent-root/src/agent/agent/write-file-session.ts +0 -238
  126. package/vendor/agent-root/src/agent/app/__test__/agent-app-service.test.ts +0 -1053
  127. package/vendor/agent-root/src/agent/app/__test__/minimal-agent-application.test.ts +0 -158
  128. package/vendor/agent-root/src/agent/app/__test__/sqlite-agent-app-store.test.ts +0 -437
  129. package/vendor/agent-root/src/agent/app/agent-app-service.ts +0 -748
  130. package/vendor/agent-root/src/agent/app/contracts.ts +0 -109
  131. package/vendor/agent-root/src/agent/app/index.ts +0 -5
  132. package/vendor/agent-root/src/agent/app/minimal-agent-application.ts +0 -151
  133. package/vendor/agent-root/src/agent/app/ports.ts +0 -72
  134. package/vendor/agent-root/src/agent/app/sqlite-agent-app-store.ts +0 -1182
  135. package/vendor/agent-root/src/agent/app/sqlite-client.ts +0 -177
  136. package/vendor/agent-root/src/agent/docs/cli-app-layer/00-README.md +0 -36
  137. package/vendor/agent-root/src/agent/docs/cli-app-layer/01-scope-and-goals.md +0 -33
  138. package/vendor/agent-root/src/agent/docs/cli-app-layer/02-architecture-overview.md +0 -40
  139. package/vendor/agent-root/src/agent/docs/cli-app-layer/03-domain-model-and-contracts.md +0 -91
  140. package/vendor/agent-root/src/agent/docs/cli-app-layer/04-ports-and-interfaces.md +0 -116
  141. package/vendor/agent-root/src/agent/docs/cli-app-layer/05-run-orchestration-and-state-machine.md +0 -52
  142. package/vendor/agent-root/src/agent/docs/cli-app-layer/06-cli-commands-and-ux.md +0 -53
  143. package/vendor/agent-root/src/agent/docs/cli-app-layer/07-storage-design-local.md +0 -52
  144. package/vendor/agent-root/src/agent/docs/cli-app-layer/08-error-and-observability.md +0 -40
  145. package/vendor/agent-root/src/agent/docs/cli-app-layer/09-security-and-policy-boundary.md +0 -19
  146. package/vendor/agent-root/src/agent/docs/cli-app-layer/10-test-plan-and-acceptance.md +0 -28
  147. package/vendor/agent-root/src/agent/docs/cli-app-layer/11-implementation-phases.md +0 -26
  148. package/vendor/agent-root/src/agent/docs/cli-app-layer/12-open-questions-and-risks.md +0 -30
  149. package/vendor/agent-root/src/agent/docs/cli-app-layer/13-sqlite-schema-fields-and-rationale.md +0 -567
  150. package/vendor/agent-root/src/agent/docs/cli-app-layer/14-project-flow-mermaid.md +0 -583
  151. package/vendor/agent-root/src/agent/docs/cli-app-layer/15-openclaw-style-project-blueprint.md +0 -972
  152. package/vendor/agent-root/src/agent/error-contract.ts +0 -154
  153. package/vendor/agent-root/src/agent/prompts/system.ts +0 -246
  154. package/vendor/agent-root/src/agent/prompts/system1.ts +0 -208
  155. package/vendor/agent-root/src/agent/storage/__test__/file-history-store.test.ts +0 -98
  156. package/vendor/agent-root/src/agent/storage/file-history-store.ts +0 -313
  157. package/vendor/agent-root/src/agent/storage/file-storage-config.ts +0 -94
  158. package/vendor/agent-root/src/agent/storage/file-system.ts +0 -31
  159. package/vendor/agent-root/src/agent/storage/file-write-service.ts +0 -21
  160. package/vendor/agent-root/src/agent/tool/__test__/base-tool.test.ts +0 -413
  161. package/vendor/agent-root/src/agent/tool/__test__/bash-policy.test.ts +0 -356
  162. package/vendor/agent-root/src/agent/tool/__test__/bash.mocked-coverage.test.ts +0 -375
  163. package/vendor/agent-root/src/agent/tool/__test__/bash.test.ts +0 -372
  164. package/vendor/agent-root/src/agent/tool/__test__/error.test.ts +0 -108
  165. package/vendor/agent-root/src/agent/tool/__test__/file-edit-tool.test.ts +0 -258
  166. package/vendor/agent-root/src/agent/tool/__test__/file-history-tools.test.ts +0 -121
  167. package/vendor/agent-root/src/agent/tool/__test__/file-read-tool.test.ts +0 -210
  168. package/vendor/agent-root/src/agent/tool/__test__/glob.test.ts +0 -139
  169. package/vendor/agent-root/src/agent/tool/__test__/grep.mocked-coverage.test.ts +0 -456
  170. package/vendor/agent-root/src/agent/tool/__test__/grep.test.ts +0 -192
  171. package/vendor/agent-root/src/agent/tool/__test__/lsp.test.ts +0 -300
  172. package/vendor/agent-root/src/agent/tool/__test__/outside-workspace-confirmation.test.ts +0 -214
  173. package/vendor/agent-root/src/agent/tool/__test__/path-security.test.ts +0 -336
  174. package/vendor/agent-root/src/agent/tool/__test__/skill-loader.test.ts +0 -494
  175. package/vendor/agent-root/src/agent/tool/__test__/skill-parser.test.ts +0 -543
  176. package/vendor/agent-root/src/agent/tool/__test__/skill-tool.test.ts +0 -172
  177. package/vendor/agent-root/src/agent/tool/__test__/task-concurrency-and-version.test.ts +0 -116
  178. package/vendor/agent-root/src/agent/tool/__test__/task-create-get-list-update.test.ts +0 -267
  179. package/vendor/agent-root/src/agent/tool/__test__/task-create.test.ts +0 -519
  180. package/vendor/agent-root/src/agent/tool/__test__/task-errors.test.ts +0 -225
  181. package/vendor/agent-root/src/agent/tool/__test__/task-output-blocking.test.ts +0 -223
  182. package/vendor/agent-root/src/agent/tool/__test__/task-output.test.ts +0 -184
  183. package/vendor/agent-root/src/agent/tool/__test__/task-parent-abort.test.ts +0 -287
  184. package/vendor/agent-root/src/agent/tool/__test__/task-real-runner-adapter.test.ts +0 -190
  185. package/vendor/agent-root/src/agent/tool/__test__/task-run-lifecycle.test.ts +0 -352
  186. package/vendor/agent-root/src/agent/tool/__test__/task-store-runner-branches.test.ts +0 -395
  187. package/vendor/agent-root/src/agent/tool/__test__/task-store.test.ts +0 -391
  188. package/vendor/agent-root/src/agent/tool/__test__/task-subagent-config-integration.test.ts +0 -176
  189. package/vendor/agent-root/src/agent/tool/__test__/task-subagent-config.test.ts +0 -68
  190. package/vendor/agent-root/src/agent/tool/__test__/task-tools-core-edges.test.ts +0 -630
  191. package/vendor/agent-root/src/agent/tool/__test__/task-tools-runtime-edges.test.ts +0 -732
  192. package/vendor/agent-root/src/agent/tool/__test__/task-types.test.ts +0 -494
  193. package/vendor/agent-root/src/agent/tool/__test__/task-utils-branches.test.ts +0 -175
  194. package/vendor/agent-root/src/agent/tool/__test__/tool-manager.test.ts +0 -505
  195. package/vendor/agent-root/src/agent/tool/__test__/types.test.ts +0 -55
  196. package/vendor/agent-root/src/agent/tool/__test__/web-fetch.test.ts +0 -244
  197. package/vendor/agent-root/src/agent/tool/__test__/web-search.test.ts +0 -290
  198. package/vendor/agent-root/src/agent/tool/__test__/write-file.test.ts +0 -368
  199. package/vendor/agent-root/src/agent/tool/base-tool.ts +0 -345
  200. package/vendor/agent-root/src/agent/tool/bash-policy.ts +0 -636
  201. package/vendor/agent-root/src/agent/tool/bash.ts +0 -688
  202. package/vendor/agent-root/src/agent/tool/error.ts +0 -131
  203. package/vendor/agent-root/src/agent/tool/file-edit-tool.ts +0 -264
  204. package/vendor/agent-root/src/agent/tool/file-history-list.ts +0 -103
  205. package/vendor/agent-root/src/agent/tool/file-history-restore.ts +0 -149
  206. package/vendor/agent-root/src/agent/tool/file-read-tool.ts +0 -211
  207. package/vendor/agent-root/src/agent/tool/glob.ts +0 -171
  208. package/vendor/agent-root/src/agent/tool/grep.ts +0 -496
  209. package/vendor/agent-root/src/agent/tool/lsp.ts +0 -481
  210. package/vendor/agent-root/src/agent/tool/path-security.ts +0 -117
  211. package/vendor/agent-root/src/agent/tool/search/common.ts +0 -153
  212. package/vendor/agent-root/src/agent/tool/skill/index.ts +0 -13
  213. package/vendor/agent-root/src/agent/tool/skill/loader.ts +0 -229
  214. package/vendor/agent-root/src/agent/tool/skill/parser.ts +0 -124
  215. package/vendor/agent-root/src/agent/tool/skill/types.ts +0 -27
  216. package/vendor/agent-root/src/agent/tool/skill-tool.ts +0 -143
  217. package/vendor/agent-root/src/agent/tool/task-create.ts +0 -186
  218. package/vendor/agent-root/src/agent/tool/task-errors.ts +0 -42
  219. package/vendor/agent-root/src/agent/tool/task-get.ts +0 -116
  220. package/vendor/agent-root/src/agent/tool/task-graph.ts +0 -78
  221. package/vendor/agent-root/src/agent/tool/task-list.ts +0 -141
  222. package/vendor/agent-root/src/agent/tool/task-mock-runner-adapter.ts +0 -232
  223. package/vendor/agent-root/src/agent/tool/task-output.ts +0 -223
  224. package/vendor/agent-root/src/agent/tool/task-parent-abort.ts +0 -115
  225. package/vendor/agent-root/src/agent/tool/task-real-runner-adapter.ts +0 -336
  226. package/vendor/agent-root/src/agent/tool/task-runner-adapter.ts +0 -55
  227. package/vendor/agent-root/src/agent/tool/task-stop.ts +0 -187
  228. package/vendor/agent-root/src/agent/tool/task-store.ts +0 -217
  229. package/vendor/agent-root/src/agent/tool/task-subagent-config.ts +0 -149
  230. package/vendor/agent-root/src/agent/tool/task-types.ts +0 -264
  231. package/vendor/agent-root/src/agent/tool/task-update.ts +0 -315
  232. package/vendor/agent-root/src/agent/tool/task.ts +0 -209
  233. package/vendor/agent-root/src/agent/tool/tool-manager.ts +0 -361
  234. package/vendor/agent-root/src/agent/tool/tool-prompts.ts +0 -242
  235. package/vendor/agent-root/src/agent/tool/types.ts +0 -116
  236. package/vendor/agent-root/src/agent/tool/web-fetch.ts +0 -227
  237. package/vendor/agent-root/src/agent/tool/web-search.ts +0 -208
  238. package/vendor/agent-root/src/agent/tool/write-file.ts +0 -497
  239. package/vendor/agent-root/src/agent/types.ts +0 -232
  240. package/vendor/agent-root/src/agent/utils/__tests__/index.test.ts +0 -18
  241. package/vendor/agent-root/src/agent/utils/__tests__/message-utils.test.ts +0 -610
  242. package/vendor/agent-root/src/agent/utils/__tests__/message.test.ts +0 -223
  243. package/vendor/agent-root/src/agent/utils/__tests__/token.test.ts +0 -42
  244. package/vendor/agent-root/src/agent/utils/index.ts +0 -16
  245. package/vendor/agent-root/src/agent/utils/message.ts +0 -171
  246. package/vendor/agent-root/src/agent/utils/token.ts +0 -28
  247. package/vendor/agent-root/src/config/__tests__/load-config-to-env.test.ts +0 -238
  248. package/vendor/agent-root/src/config/__tests__/loader.test.ts +0 -361
  249. package/vendor/agent-root/src/config/__tests__/runtime.test.ts +0 -88
  250. package/vendor/agent-root/src/config/index.ts +0 -55
  251. package/vendor/agent-root/src/config/loader.ts +0 -494
  252. package/vendor/agent-root/src/config/paths.ts +0 -30
  253. package/vendor/agent-root/src/config/runtime.ts +0 -163
  254. package/vendor/agent-root/src/config/types.ts +0 -96
  255. package/vendor/agent-root/src/logger/index.ts +0 -57
  256. package/vendor/agent-root/src/logger/logger.ts +0 -819
  257. package/vendor/agent-root/src/logger/types.ts +0 -150
  258. package/vendor/agent-root/src/providers/__tests__/errors.test.ts +0 -441
  259. package/vendor/agent-root/src/providers/__tests__/index.test.ts +0 -16
  260. package/vendor/agent-root/src/providers/__tests__/openai-compatible.options.test.ts +0 -318
  261. package/vendor/agent-root/src/providers/__tests__/openai-compatible.test.ts +0 -600
  262. package/vendor/agent-root/src/providers/__tests__/registry.test.ts +0 -523
  263. package/vendor/agent-root/src/providers/__tests__/responses-adapter.test.ts +0 -298
  264. package/vendor/agent-root/src/providers/adapters/__tests__/anthropic.test.ts +0 -354
  265. package/vendor/agent-root/src/providers/adapters/__tests__/kimi.test.ts +0 -58
  266. package/vendor/agent-root/src/providers/adapters/__tests__/standard.test.ts +0 -261
  267. package/vendor/agent-root/src/providers/adapters/anthropic.ts +0 -572
  268. package/vendor/agent-root/src/providers/adapters/base.ts +0 -131
  269. package/vendor/agent-root/src/providers/adapters/kimi.ts +0 -48
  270. package/vendor/agent-root/src/providers/adapters/responses.ts +0 -732
  271. package/vendor/agent-root/src/providers/adapters/standard.ts +0 -120
  272. package/vendor/agent-root/src/providers/http/__tests__/client.timeout.test.ts +0 -313
  273. package/vendor/agent-root/src/providers/http/client.ts +0 -289
  274. package/vendor/agent-root/src/providers/http/stream-parser.ts +0 -109
  275. package/vendor/agent-root/src/providers/index.ts +0 -76
  276. package/vendor/agent-root/src/providers/kimi-headers.ts +0 -177
  277. package/vendor/agent-root/src/providers/openai-compatible.ts +0 -387
  278. package/vendor/agent-root/src/providers/registry/model-config.ts +0 -477
  279. package/vendor/agent-root/src/providers/registry/provider-factory.ts +0 -127
  280. package/vendor/agent-root/src/providers/registry.ts +0 -135
  281. package/vendor/agent-root/src/providers/types/api.ts +0 -284
  282. package/vendor/agent-root/src/providers/types/config.ts +0 -58
  283. package/vendor/agent-root/src/providers/types/errors.ts +0 -323
  284. package/vendor/agent-root/src/providers/types/index.ts +0 -72
  285. package/vendor/agent-root/src/providers/types/provider.ts +0 -45
  286. package/vendor/agent-root/src/providers/types/registry.ts +0 -68
@@ -1,819 +0,0 @@
1
- /**
2
- * Logger 核心实现
3
- *
4
- * 简洁实用的日志系统,支持:
5
- * - 多级别日志 (TRACE ~ FATAL)
6
- * - 多输出目标 (Console, File)
7
- * - 结构化日志 (JSON/Pretty)
8
- * - 日志轮转
9
- * - 任意数据存储
10
- * - 敏感字段脱敏
11
- * - 异步上下文隔离
12
- */
13
-
14
- import * as fs from 'node:fs';
15
- import * as path from 'node:path';
16
- import { AsyncLocalStorage } from 'node:async_hooks';
17
- import type {
18
- LoggerConfig,
19
- LogRecord,
20
- LogLevel,
21
- LogContext,
22
- LogError,
23
- LogMiddleware,
24
- FileConfig,
25
- ConsoleConfig,
26
- ITransport,
27
- LogCallback,
28
- } from './types';
29
- import { LogLevel as Lvl, LogLevelName } from './types';
30
-
31
- // =============================================================================
32
- // 默认配置
33
- // =============================================================================
34
-
35
- const DEFAULT_SENSITIVE_FIELDS = [
36
- 'apiKey',
37
- 'api_key',
38
- 'password',
39
- 'token',
40
- 'secret',
41
- 'authorization',
42
- 'credential',
43
- ];
44
-
45
- const DEFAULT_CONFIG: Required<Omit<LoggerConfig, 'defaultContext'>> & {
46
- defaultContext: LogContext;
47
- } = {
48
- service: 'app',
49
- env: 'development',
50
- level: Lvl.INFO,
51
- defaultContext: {},
52
- console: {
53
- enabled: true,
54
- format: 'pretty',
55
- colorize: true,
56
- },
57
- file: {
58
- enabled: false,
59
- filepath: './logs/app.log',
60
- format: 'json',
61
- maxSize: 10 * 1024 * 1024, // 10MB
62
- maxFiles: 5,
63
- },
64
- sensitiveFields: DEFAULT_SENSITIVE_FIELDS,
65
- transports: [],
66
- onLog: undefined as unknown as LogCallback,
67
- };
68
-
69
- // =============================================================================
70
- // 工具函数
71
- // =============================================================================
72
-
73
- /**
74
- * 安全序列化任意数据
75
- */
76
- function safeStringify(data: unknown): string {
77
- return stringifyWithCircular(data);
78
- }
79
-
80
- /**
81
- * 带循环引用检测的序列化
82
- */
83
- function stringifyWithCircular(data: unknown, seen: WeakSet<object> = new WeakSet()): string {
84
- if (data === null || data === undefined) {
85
- return JSON.stringify(data);
86
- }
87
-
88
- if (typeof data !== 'object') {
89
- try {
90
- return JSON.stringify(data);
91
- } catch {
92
- return JSON.stringify(String(data));
93
- }
94
- }
95
-
96
- // 处理特殊对象类型
97
- if (data instanceof Error) {
98
- return JSON.stringify({
99
- __type: 'Error',
100
- name: data.name,
101
- message: data.message,
102
- stack: data.stack,
103
- });
104
- }
105
-
106
- if (data instanceof Date) {
107
- return JSON.stringify(data.toISOString());
108
- }
109
-
110
- if (data instanceof Map) {
111
- const obj: Record<string, unknown> = {};
112
- for (const [k, v] of data) {
113
- obj[String(k)] = v;
114
- }
115
- return stringifyWithCircular(obj, seen);
116
- }
117
-
118
- if (data instanceof Set) {
119
- return stringifyWithCircular(Array.from(data), seen);
120
- }
121
-
122
- if (Buffer.isBuffer(data)) {
123
- return JSON.stringify(data.toString('base64'));
124
- }
125
-
126
- if (seen.has(data as object)) return '"[Circular]"';
127
- seen.add(data as object);
128
-
129
- if (Array.isArray(data)) {
130
- const items = data.map((item) => stringifyWithCircular(item, seen));
131
- return '[' + items.join(', ') + ']';
132
- }
133
-
134
- const result: Record<string, unknown> = {};
135
- for (const key of Object.keys(data as object)) {
136
- const value = (data as Record<string, unknown>)[key];
137
- if (typeof value === 'object' && value !== null) {
138
- result[key] = JSON.parse(stringifyWithCircular(value, seen));
139
- } else {
140
- result[key] = value;
141
- }
142
- }
143
-
144
- try {
145
- return JSON.stringify(result);
146
- } catch {
147
- return '"[Non-serializable]"';
148
- }
149
- }
150
-
151
- /**
152
- * 脱敏对象
153
- */
154
- function sanitize(
155
- obj: unknown,
156
- sensitiveFields: string[],
157
- seen: WeakSet<object> = new WeakSet()
158
- ): unknown {
159
- if (!obj || typeof obj !== 'object') return obj;
160
- if (seen.has(obj as object)) return '[Circular]';
161
- seen.add(obj as object);
162
-
163
- // 处理特殊类型
164
- if (obj instanceof Error) {
165
- return {
166
- __type: 'Error',
167
- name: obj.name,
168
- message: obj.message,
169
- stack: obj.stack,
170
- };
171
- }
172
-
173
- if (obj instanceof Date) {
174
- return obj.toISOString();
175
- }
176
-
177
- if (obj instanceof Map) {
178
- const result: Record<string, unknown> = {};
179
- for (const [k, v] of obj) {
180
- result[String(k)] = sanitize(v, sensitiveFields, seen);
181
- }
182
- return result;
183
- }
184
-
185
- if (obj instanceof Set) {
186
- return Array.from(obj).map((item) => sanitize(item, sensitiveFields, seen));
187
- }
188
-
189
- if (Buffer.isBuffer(obj)) {
190
- return obj.toString('base64');
191
- }
192
-
193
- if (Array.isArray(obj)) {
194
- return obj.map((item) => sanitize(item, sensitiveFields, seen));
195
- }
196
-
197
- const result: Record<string, unknown> = {};
198
- for (const [key, value] of Object.entries(obj as Record<string, unknown>)) {
199
- if (sensitiveFields.some((f) => key.toLowerCase().includes(f.toLowerCase()))) {
200
- result[key] = '[REDACTED]';
201
- } else if (typeof value === 'object' && value !== null) {
202
- result[key] = sanitize(value, sensitiveFields, seen);
203
- } else {
204
- result[key] = value;
205
- }
206
- }
207
- return result;
208
- }
209
-
210
- // =============================================================================
211
- // 格式化器
212
- // =============================================================================
213
-
214
- /** ANSI 颜色代码 */
215
- const Colors = {
216
- reset: '\x1b[0m',
217
- bold: '\x1b[1m',
218
- dim: '\x1b[2m',
219
- red: '\x1b[31m',
220
- green: '\x1b[32m',
221
- yellow: '\x1b[33m',
222
- cyan: '\x1b[36m',
223
- bgRed: '\x1b[41m',
224
- white: '\x1b[37m',
225
- };
226
-
227
- const LevelColors: Record<LogLevel, string> = {
228
- [Lvl.TRACE]: Colors.dim,
229
- [Lvl.DEBUG]: Colors.cyan,
230
- [Lvl.INFO]: Colors.green,
231
- [Lvl.WARN]: Colors.yellow,
232
- [Lvl.ERROR]: Colors.red,
233
- [Lvl.FATAL]: Colors.bgRed + Colors.white,
234
- };
235
-
236
- /**
237
- * 格式化为 JSON
238
- */
239
- function formatJson(record: LogRecord): string {
240
- const output: Record<string, unknown> = {
241
- '@timestamp': record.timestamp,
242
- '@level': record.levelName,
243
- '@message': record.message,
244
- '@context': record.context, // 始终包含上下文
245
- };
246
-
247
- if (record.module) output['@module'] = record.module;
248
- if (record.error) output['@error'] = record.error;
249
- if (record.data !== undefined) output['@data'] = record.data;
250
-
251
- return safeStringify(output);
252
- }
253
-
254
- /**
255
- * 格式化为可读文本
256
- */
257
- function formatPretty(record: LogRecord, colorize: boolean): string {
258
- const color = (text: string, code: string) => (colorize ? `${code}${text}${Colors.reset}` : text);
259
-
260
- const parts: string[] = [];
261
-
262
- // 时间戳
263
- const date = new Date(record.timestamp);
264
- const time =
265
- date.toLocaleTimeString('zh-CN', {
266
- hour: '2-digit',
267
- minute: '2-digit',
268
- second: '2-digit',
269
- }) +
270
- '.' +
271
- String(date.getMilliseconds()).padStart(3, '0');
272
- parts.push(color(time, Colors.dim));
273
-
274
- // 级别
275
- const levelName = LogLevelName[record.level].padEnd(5);
276
- parts.push(color(levelName, LevelColors[record.level] + Colors.bold));
277
-
278
- // 模块
279
- if (record.module) {
280
- parts.push(color(`[${record.module}]`, Colors.cyan));
281
- }
282
-
283
- // 消息
284
- parts.push(record.message);
285
-
286
- // 上下文(最多5个字段)
287
- if (Object.keys(record.context).length > 0) {
288
- const pairs = Object.entries(record.context)
289
- .slice(0, 5)
290
- .map(([k, v]) => {
291
- const str = typeof v === 'object' ? safeStringify(v) : String(v);
292
- const truncated = str.length > 30 ? str.slice(0, 30) + '...' : str;
293
- return `${k}=${truncated}`;
294
- });
295
- parts.push(color(`(${pairs.join(', ')})`, Colors.dim));
296
- }
297
-
298
- let output = parts.join(' ');
299
-
300
- // 错误信息
301
- if (record.error) {
302
- output += '\n' + formatErrorDisplay(record.error, colorize);
303
- }
304
-
305
- // 数据
306
- if (record.data !== undefined) {
307
- output += '\n' + color(safeStringify(record.data), Colors.dim);
308
- }
309
-
310
- return output;
311
- }
312
-
313
- function formatErrorDisplay(error: LogError, colorize: boolean): string {
314
- const color = (text: string, code: string) => (colorize ? `${code}${text}${Colors.reset}` : text);
315
- const lines: string[] = [];
316
-
317
- lines.push(color('┌─ Error ─────────────────────────────', Colors.red));
318
- lines.push(color(`│ Type: ${error.name}`, Colors.red));
319
- lines.push(color(`│ Message: ${error.message}`, Colors.red));
320
- if (error.code) lines.push(color(`│ Code: ${error.code}`, Colors.red));
321
- if (error.stack) {
322
- lines.push(color('│ Stack:', Colors.red));
323
- for (const line of error.stack.split('\n').slice(0, 8)) {
324
- lines.push(color(`│ ${line}`, Colors.dim));
325
- }
326
- }
327
- lines.push(color('└──────────────────────────────────────', Colors.red));
328
-
329
- return lines.join('\n');
330
- }
331
-
332
- // =============================================================================
333
- // 上下文管理器
334
- // =============================================================================
335
-
336
- class ContextManager {
337
- private static instance: ContextManager;
338
- private readonly storage = new AsyncLocalStorage<LogContext>();
339
- private fallback: LogContext = {};
340
-
341
- static getInstance(): ContextManager {
342
- if (!ContextManager.instance) {
343
- ContextManager.instance = new ContextManager();
344
- }
345
- return ContextManager.instance;
346
- }
347
-
348
- get(): LogContext {
349
- return this.storage.getStore() ?? this.fallback;
350
- }
351
-
352
- set(context: LogContext): void {
353
- this.fallback = context;
354
- this.storage.enterWith(context);
355
- }
356
-
357
- update(context: Partial<LogContext>): void {
358
- const next = { ...this.get(), ...context };
359
- this.fallback = next;
360
- this.storage.enterWith(next);
361
- }
362
-
363
- clear(): void {
364
- this.fallback = {};
365
- this.storage.enterWith({});
366
- }
367
-
368
- run<T>(context: LogContext, fn: () => T): T {
369
- return this.storage.run({ ...this.get(), ...context }, fn);
370
- }
371
- }
372
-
373
- export const contextManager = ContextManager.getInstance();
374
-
375
- // =============================================================================
376
- // Transport 实现
377
- // =============================================================================
378
-
379
- /**
380
- * 控制台输出
381
- */
382
- class ConsoleTransport implements ITransport {
383
- readonly name = 'console';
384
- private config: {
385
- enabled: boolean;
386
- format: 'json' | 'pretty';
387
- colorize: boolean;
388
- level?: LogLevel;
389
- };
390
-
391
- constructor(config: ConsoleConfig) {
392
- this.config = {
393
- format: 'pretty',
394
- colorize: true,
395
- ...config,
396
- enabled: config.enabled ?? true,
397
- };
398
- }
399
-
400
- write(record: LogRecord, globalLevel: LogLevel): void {
401
- if (!this.config.enabled) return;
402
- if (record.level < (this.config.level ?? globalLevel)) return;
403
-
404
- const formatted =
405
- this.config.format === 'json'
406
- ? formatJson(record)
407
- : formatPretty(record, this.config.colorize);
408
-
409
- // ERROR/FATAL 输出到 stderr
410
- const stream = record.level >= Lvl.ERROR ? process.stderr : process.stdout;
411
- stream.write(formatted + '\n');
412
- }
413
- }
414
-
415
- /**
416
- * 文件输出(支持日志轮转)
417
- */
418
- class FileTransport implements ITransport {
419
- readonly name = 'file';
420
- private config: {
421
- enabled: boolean;
422
- filepath: string;
423
- format: 'json' | 'pretty';
424
- level?: LogLevel;
425
- maxSize: number;
426
- maxFiles: number;
427
- };
428
- private stream: fs.WriteStream | null = null;
429
- private currentSize = 0;
430
-
431
- constructor(config: FileConfig) {
432
- this.config = {
433
- format: 'json',
434
- maxSize: 10 * 1024 * 1024,
435
- maxFiles: 5,
436
- ...config,
437
- enabled: config.enabled ?? false,
438
- filepath: config.filepath ?? './logs/app.log',
439
- };
440
-
441
- if (this.config.enabled) {
442
- this.initStream();
443
- }
444
- }
445
-
446
- private initStream(): void {
447
- const dir = path.dirname(this.config.filepath);
448
- if (!fs.existsSync(dir)) {
449
- fs.mkdirSync(dir, { recursive: true });
450
- }
451
-
452
- this.stream = fs.createWriteStream(this.config.filepath, { flags: 'a', encoding: 'utf8' });
453
-
454
- try {
455
- this.currentSize = fs.statSync(this.config.filepath).size;
456
- } catch {
457
- this.currentSize = 0;
458
- }
459
-
460
- this.stream.on('error', (err) => {
461
- console.error(`[Logger] File transport error: ${err.message}`);
462
- });
463
- }
464
-
465
- write(record: LogRecord, globalLevel: LogLevel): void {
466
- if (!this.config.enabled || !this.stream) return;
467
- if (record.level < (this.config.level ?? globalLevel)) return;
468
-
469
- const formatted =
470
- this.config.format === 'pretty' ? formatPretty(record, false) : formatJson(record);
471
-
472
- const content = formatted + '\n';
473
- this.stream.write(content);
474
- this.currentSize += Buffer.byteLength(content, 'utf8');
475
-
476
- this.checkRotation();
477
- }
478
-
479
- private checkRotation(): void {
480
- if (this.currentSize < this.config.maxSize) return;
481
-
482
- // 关闭当前流
483
- if (this.stream) {
484
- this.stream.end();
485
- this.stream = null;
486
- }
487
-
488
- const dir = path.dirname(this.config.filepath);
489
- const ext = path.extname(this.config.filepath);
490
- const base = path.basename(this.config.filepath, ext);
491
-
492
- // 轮转文件
493
- for (let i = this.config.maxFiles - 1; i >= 1; i--) {
494
- const oldFile = path.join(dir, `${base}.${i}${ext}`);
495
- const newFile = path.join(dir, `${base}.${i + 1}${ext}`);
496
- try {
497
- if (fs.existsSync(oldFile)) {
498
- if (i === this.config.maxFiles - 1) {
499
- fs.unlinkSync(oldFile);
500
- } else {
501
- fs.renameSync(oldFile, newFile);
502
- }
503
- }
504
- } catch (err) {
505
- console.error(`[Logger] Rotation error: ${(err as Error).message}`);
506
- }
507
- }
508
-
509
- // 重命名当前文件
510
- try {
511
- fs.renameSync(this.config.filepath, path.join(dir, `${base}.1${ext}`));
512
- } catch (err) {
513
- console.error(`[Logger] Rename error: ${(err as Error).message}`);
514
- }
515
-
516
- this.initStream();
517
- }
518
-
519
- close(): void {
520
- if (this.stream) {
521
- this.stream.end();
522
- this.stream = null;
523
- }
524
- }
525
- }
526
-
527
- // =============================================================================
528
- // Logger 类
529
- // =============================================================================
530
-
531
- /**
532
- * 日志器类
533
- */
534
- export class Logger {
535
- private config: Required<Omit<LoggerConfig, 'defaultContext' | 'transports' | 'onLog'>> & {
536
- defaultContext: LogContext;
537
- transports?: ITransport[];
538
- onLog?: LogCallback;
539
- };
540
- private middlewares: LogMiddleware[] = [];
541
- private consoleTransport: ConsoleTransport;
542
- private fileTransport: FileTransport;
543
- private customTransports: ITransport[] = [];
544
- private closed = false;
545
-
546
- constructor(config?: Partial<LoggerConfig>) {
547
- this.config = {
548
- ...DEFAULT_CONFIG,
549
- ...config,
550
- console: { ...DEFAULT_CONFIG.console, ...config?.console },
551
- file: { ...DEFAULT_CONFIG.file, ...config?.file },
552
- defaultContext: config?.defaultContext ?? {},
553
- sensitiveFields: config?.sensitiveFields ?? DEFAULT_CONFIG.sensitiveFields,
554
- transports: config?.transports,
555
- onLog: config?.onLog,
556
- };
557
-
558
- this.consoleTransport = new ConsoleTransport(this.config.console);
559
- this.fileTransport = new FileTransport(this.config.file);
560
-
561
- this.customTransports = config?.transports ?? [];
562
-
563
- // 默认上下文中间件
564
- if (Object.keys(this.config.defaultContext).length > 0) {
565
- this.middlewares.push((record, next) => {
566
- record.context = { ...this.config.defaultContext, ...record.context };
567
- next();
568
- });
569
- }
570
-
571
- // 敏感字段脱敏中间件
572
- if (this.config.sensitiveFields.length > 0) {
573
- this.middlewares.push((record, next) => {
574
- record.context = sanitize(record.context, this.config.sensitiveFields) as LogContext;
575
- if (record.data !== undefined) {
576
- record.data = sanitize(record.data, this.config.sensitiveFields);
577
- }
578
- next();
579
- });
580
- }
581
- }
582
-
583
- /**
584
- * 添加中间件
585
- */
586
- use(middleware: LogMiddleware): this {
587
- this.middlewares.push(middleware);
588
- return this;
589
- }
590
-
591
- /**
592
- * 添加自定义 Transport
593
- */
594
- addTransport(transport: ITransport): this {
595
- this.customTransports.push(transport);
596
- return this;
597
- }
598
-
599
- /**
600
- * 创建日志记录
601
- */
602
- private createRecord(
603
- level: LogLevel,
604
- message: string,
605
- context?: LogContext,
606
- error?: Error,
607
- data?: unknown
608
- ): LogRecord {
609
- const globalContext = contextManager.get();
610
- const record: LogRecord = {
611
- timestamp: new Date().toISOString(),
612
- level,
613
- levelName: LogLevelName[level],
614
- message,
615
- context: { ...globalContext, ...context },
616
- data,
617
- };
618
-
619
- if (error) {
620
- record.error = {
621
- name: error.name,
622
- message: error.message,
623
- stack: error.stack,
624
- };
625
- }
626
-
627
- return record;
628
- }
629
-
630
- /**
631
- * 执行中间件链
632
- */
633
- private executeMiddlewares(record: LogRecord): void {
634
- let index = 0;
635
- const next = () => {
636
- if (index < this.middlewares.length) {
637
- this.middlewares[index++](record, next);
638
- }
639
- };
640
- next();
641
- }
642
-
643
- /**
644
- * 写入日志
645
- */
646
- private log(record: LogRecord): void {
647
- if (this.closed) return;
648
- if (record.level < this.config.level) return;
649
-
650
- this.executeMiddlewares(record);
651
-
652
- // 写入内置 Transport
653
- this.consoleTransport.write(record, this.config.level);
654
- this.fileTransport.write(record, this.config.level);
655
-
656
- // 写入自定义 Transport
657
- for (const transport of this.customTransports) {
658
- try {
659
- transport.write(record, this.config.level);
660
- } catch (err) {
661
- console.error(`[Logger] Transport "${transport.name ?? 'unknown'}" error:`, err);
662
- }
663
- }
664
-
665
- // 调用 onLog 回调
666
- if (this.config.onLog) {
667
- try {
668
- this.config.onLog(record);
669
- } catch (err) {
670
- console.error('[Logger] onLog callback error:', err);
671
- }
672
- }
673
- }
674
-
675
- // ---------------------------------------------------------------------------
676
- // 日志方法
677
- // ---------------------------------------------------------------------------
678
-
679
- trace(message: string, context?: LogContext): void {
680
- this.log(this.createRecord(Lvl.TRACE, message, context));
681
- }
682
-
683
- debug(message: string, context?: LogContext, data?: unknown): void {
684
- this.log(this.createRecord(Lvl.DEBUG, message, context, undefined, data));
685
- }
686
-
687
- info(message: string, context?: LogContext, data?: unknown): void {
688
- this.log(this.createRecord(Lvl.INFO, message, context, undefined, data));
689
- }
690
-
691
- warn(message: string, context?: LogContext, data?: unknown): void {
692
- this.log(this.createRecord(Lvl.WARN, message, context, undefined, data));
693
- }
694
-
695
- error(message: string, error?: Error | unknown, context?: LogContext): void {
696
- const err = error instanceof Error ? error : undefined;
697
- const data = error !== undefined && !(error instanceof Error) ? error : undefined;
698
- this.log(this.createRecord(Lvl.ERROR, message, context, err, data));
699
- }
700
-
701
- fatal(message: string, error?: Error | unknown, context?: LogContext): void {
702
- const err = error instanceof Error ? error : undefined;
703
- const data = error !== undefined && !(error instanceof Error) ? error : undefined;
704
- this.log(this.createRecord(Lvl.FATAL, message, context, err, data));
705
- }
706
-
707
- /**
708
- * 直接记录 LogRecord
709
- */
710
- write(record: LogRecord): void {
711
- this.log(record);
712
- }
713
-
714
- // ---------------------------------------------------------------------------
715
- // 子日志器
716
- // ---------------------------------------------------------------------------
717
-
718
- child(module: string, additionalContext?: LogContext): ChildLogger {
719
- return new ChildLogger(this, module, additionalContext);
720
- }
721
-
722
- // ---------------------------------------------------------------------------
723
- // 生命周期
724
- // ---------------------------------------------------------------------------
725
-
726
- close(): void {
727
- if (this.closed) return;
728
- this.closed = true;
729
- this.fileTransport.close();
730
-
731
- // 关闭自定义 Transport
732
- for (const transport of this.customTransports) {
733
- if (transport.close) {
734
- try {
735
- transport.close();
736
- } catch (err) {
737
- console.error(`[Logger] Transport "${transport.name ?? 'unknown'}" close error:`, err);
738
- }
739
- }
740
- }
741
- }
742
-
743
- getConfig(): Readonly<typeof this.config> {
744
- // 返回浅拷贝,避免外部修改内部配置
745
- return {
746
- ...this.config,
747
- console: { ...this.config.console },
748
- file: { ...this.config.file },
749
- sensitiveFields: [...this.config.sensitiveFields],
750
- };
751
- }
752
- }
753
-
754
- /**
755
- * 子日志器
756
- */
757
- export class ChildLogger {
758
- constructor(
759
- private parent: Logger,
760
- private module: string,
761
- private context: LogContext = {}
762
- ) {}
763
-
764
- private merge(ctx?: LogContext): LogContext {
765
- return { ...this.context, ...ctx };
766
- }
767
-
768
- trace(message: string, context?: LogContext): void {
769
- this.parent.trace(`[${this.module}] ${message}`, this.merge(context));
770
- }
771
-
772
- debug(message: string, context?: LogContext, data?: unknown): void {
773
- this.parent.debug(`[${this.module}] ${message}`, this.merge(context), data);
774
- }
775
-
776
- info(message: string, context?: LogContext, data?: unknown): void {
777
- this.parent.info(`[${this.module}] ${message}`, this.merge(context), data);
778
- }
779
-
780
- warn(message: string, context?: LogContext, data?: unknown): void {
781
- this.parent.warn(`[${this.module}] ${message}`, this.merge(context), data);
782
- }
783
-
784
- error(message: string, error?: Error | unknown, context?: LogContext): void {
785
- this.parent.error(`[${this.module}] ${message}`, error, this.merge(context));
786
- }
787
-
788
- fatal(message: string, error?: Error | unknown, context?: LogContext): void {
789
- this.parent.fatal(`[${this.module}] ${message}`, error, this.merge(context));
790
- }
791
-
792
- child(subModule: string, additionalContext?: LogContext): ChildLogger {
793
- return new ChildLogger(this.parent, `${this.module}:${subModule}`, {
794
- ...this.context,
795
- ...additionalContext,
796
- });
797
- }
798
- }
799
-
800
- // =============================================================================
801
- // 全局实例
802
- // =============================================================================
803
-
804
- let defaultLogger: Logger | null = null;
805
-
806
- export function getLogger(): Logger {
807
- if (!defaultLogger) {
808
- defaultLogger = new Logger();
809
- }
810
- return defaultLogger;
811
- }
812
-
813
- export function setDefaultLogger(logger: Logger): void {
814
- defaultLogger = logger;
815
- }
816
-
817
- export function createLogger(config?: Partial<LoggerConfig>): Logger {
818
- return new Logger(config);
819
- }