@planet-matrix/mobius-model 0.5.0 → 0.9.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/CHANGELOG.md +61 -0
- package/README.md +123 -36
- package/dist/index.js +715 -4
- package/dist/index.js.map +981 -13
- package/oxlint.config.ts +6 -0
- package/package.json +36 -18
- package/src/abort/README.md +92 -0
- package/src/abort/abort-manager.ts +278 -0
- package/src/abort/abort-signal-listener-manager.ts +81 -0
- package/src/abort/index.ts +2 -0
- package/src/ai/README.md +1 -0
- package/src/ai/ai.ts +107 -0
- package/src/ai/chat-completion-ai/aihubmix-chat-completion.ts +78 -0
- package/src/ai/chat-completion-ai/chat-completion-ai.ts +270 -0
- package/src/ai/chat-completion-ai/chat-completion.ts +189 -0
- package/src/ai/chat-completion-ai/index.ts +7 -0
- package/src/ai/chat-completion-ai/lingyiwanwu-chat-completion.ts +78 -0
- package/src/ai/chat-completion-ai/ohmygpt-chat-completion.ts +78 -0
- package/src/ai/chat-completion-ai/openai-next-chat-completion.ts +78 -0
- package/src/ai/embedding-ai/embedding-ai.ts +63 -0
- package/src/ai/embedding-ai/embedding.ts +50 -0
- package/src/ai/embedding-ai/index.ts +4 -0
- package/src/ai/embedding-ai/openai-next-embedding.ts +23 -0
- package/src/ai/index.ts +4 -0
- package/src/aio/README.md +100 -0
- package/src/aio/content.ts +141 -0
- package/src/aio/index.ts +3 -0
- package/src/aio/json.ts +127 -0
- package/src/aio/prompt.ts +246 -0
- package/src/basic/README.md +72 -116
- package/src/basic/error.ts +19 -5
- package/src/basic/function.ts +83 -64
- package/src/basic/index.ts +1 -0
- package/src/basic/is.ts +152 -71
- package/src/basic/promise.ts +29 -8
- package/src/basic/schedule.ts +111 -0
- package/src/basic/stream.ts +135 -25
- package/src/basic/string.ts +2 -33
- package/src/color/README.md +105 -0
- package/src/color/index.ts +3 -0
- package/src/color/internal.ts +42 -0
- package/src/color/rgb/analyze.ts +236 -0
- package/src/color/rgb/construct.ts +130 -0
- package/src/color/rgb/convert.ts +227 -0
- package/src/color/rgb/derive.ts +303 -0
- package/src/color/rgb/index.ts +6 -0
- package/src/color/rgb/internal.ts +208 -0
- package/src/color/rgb/parse.ts +302 -0
- package/src/color/rgb/serialize.ts +144 -0
- package/src/color/types.ts +57 -0
- package/src/color/xyz/analyze.ts +80 -0
- package/src/color/xyz/construct.ts +19 -0
- package/src/color/xyz/convert.ts +71 -0
- package/src/color/xyz/index.ts +3 -0
- package/src/color/xyz/internal.ts +23 -0
- package/src/credential/README.md +107 -0
- package/src/credential/api-key.ts +158 -0
- package/src/credential/bearer.ts +73 -0
- package/src/credential/index.ts +4 -0
- package/src/credential/json-web-token.ts +96 -0
- package/src/credential/password.ts +170 -0
- package/src/cron/README.md +86 -0
- package/src/cron/cron.ts +87 -0
- package/src/cron/index.ts +1 -0
- package/src/css/README.md +93 -0
- package/src/css/class.ts +559 -0
- package/src/css/index.ts +1 -0
- package/src/drizzle/README.md +1 -0
- package/src/drizzle/drizzle.ts +1 -0
- package/src/drizzle/helper.ts +47 -0
- package/src/drizzle/index.ts +5 -0
- package/src/drizzle/infer.ts +52 -0
- package/src/drizzle/kysely.ts +8 -0
- package/src/drizzle/pagination.ts +200 -0
- package/src/email/README.md +1 -0
- package/src/email/index.ts +1 -0
- package/src/email/resend.ts +25 -0
- package/src/encoding/README.md +66 -79
- package/src/encoding/base64.ts +13 -4
- package/src/environment/README.md +97 -0
- package/src/environment/basic.ts +26 -0
- package/src/environment/device.ts +311 -0
- package/src/environment/feature.ts +285 -0
- package/src/environment/geo.ts +337 -0
- package/src/environment/index.ts +7 -0
- package/src/environment/runtime.ts +400 -0
- package/src/environment/snapshot.ts +60 -0
- package/src/environment/variable.ts +239 -0
- package/src/event/README.md +90 -0
- package/src/event/class-event-proxy.ts +229 -0
- package/src/event/common.ts +29 -0
- package/src/event/event-manager.ts +203 -0
- package/src/event/index.ts +4 -0
- package/src/event/instance-event-proxy.ts +187 -0
- package/src/event/internal.ts +24 -0
- package/src/exception/README.md +96 -0
- package/src/exception/browser.ts +219 -0
- package/src/exception/index.ts +4 -0
- package/src/exception/nodejs.ts +169 -0
- package/src/exception/normalize.ts +106 -0
- package/src/exception/types.ts +99 -0
- package/src/form/README.md +25 -0
- package/src/form/index.ts +1 -0
- package/src/form/inputor-controller/base.ts +874 -0
- package/src/form/inputor-controller/boolean.ts +39 -0
- package/src/form/inputor-controller/file.ts +39 -0
- package/src/form/inputor-controller/form.ts +181 -0
- package/src/form/inputor-controller/helper.ts +117 -0
- package/src/form/inputor-controller/index.ts +17 -0
- package/src/form/inputor-controller/multi-select.ts +99 -0
- package/src/form/inputor-controller/number.ts +116 -0
- package/src/form/inputor-controller/select.ts +109 -0
- package/src/form/inputor-controller/text.ts +82 -0
- package/src/http/READMD.md +1 -0
- package/src/http/api/api-core.ts +84 -0
- package/src/http/api/api-handler.ts +79 -0
- package/src/http/api/api-host.ts +47 -0
- package/src/http/api/api-result.ts +56 -0
- package/src/http/api/api-schema.ts +154 -0
- package/src/http/api/api-server.ts +130 -0
- package/src/http/api/api-test.ts +142 -0
- package/src/http/api/api-type.ts +37 -0
- package/src/http/api/api.ts +81 -0
- package/src/http/api/index.ts +11 -0
- package/src/http/api-adapter/api-core-node-http.ts +260 -0
- package/src/http/api-adapter/api-host-node-http.ts +156 -0
- package/src/http/api-adapter/api-result-arktype.ts +297 -0
- package/src/http/api-adapter/api-result-zod.ts +286 -0
- package/src/http/api-adapter/index.ts +5 -0
- package/src/http/bin/gen-api-list/gen-api-list.ts +126 -0
- package/src/http/bin/gen-api-list/index.ts +1 -0
- package/src/http/bin/gen-api-test/gen-api-test.ts +136 -0
- package/src/http/bin/gen-api-test/index.ts +1 -0
- package/src/http/bin/gen-api-type/calc-code.ts +25 -0
- package/src/http/bin/gen-api-type/gen-api-type.ts +127 -0
- package/src/http/bin/gen-api-type/index.ts +2 -0
- package/src/http/bin/index.ts +2 -0
- package/src/http/index.ts +3 -0
- package/src/huawei/README.md +1 -0
- package/src/huawei/index.ts +2 -0
- package/src/huawei/moderation/index.ts +1 -0
- package/src/huawei/moderation/moderation.ts +355 -0
- package/src/huawei/obs/esdk-obs-nodejs.d.ts +87 -0
- package/src/huawei/obs/index.ts +1 -0
- package/src/huawei/obs/obs.ts +42 -0
- package/src/identifier/README.md +92 -0
- package/src/identifier/id.ts +119 -0
- package/src/identifier/index.ts +2 -0
- package/src/identifier/uuid.ts +187 -0
- package/src/index.ts +33 -1
- package/src/json/README.md +92 -0
- package/src/json/index.ts +1 -0
- package/src/json/repair.ts +18 -0
- package/src/log/README.md +79 -0
- package/src/log/index.ts +5 -0
- package/src/log/log-emitter.ts +72 -0
- package/src/log/log-record.ts +10 -0
- package/src/log/log-scheduler.ts +74 -0
- package/src/log/log-type.ts +8 -0
- package/src/log/logger.ts +554 -0
- package/src/openai/README.md +1 -0
- package/src/openai/index.ts +1 -0
- package/src/openai/openai.ts +510 -0
- package/src/orchestration/README.md +91 -0
- package/src/orchestration/coordination/barrier.ts +214 -0
- package/src/orchestration/coordination/count-down-latch.ts +215 -0
- package/src/orchestration/coordination/errors.ts +98 -0
- package/src/orchestration/coordination/index.ts +16 -0
- package/src/orchestration/coordination/internal/wait-constraints.ts +95 -0
- package/src/orchestration/coordination/internal/wait-queue.ts +109 -0
- package/src/orchestration/coordination/keyed-lock.ts +168 -0
- package/src/orchestration/coordination/mutex.ts +257 -0
- package/src/orchestration/coordination/permit.ts +127 -0
- package/src/orchestration/coordination/read-write-lock.ts +444 -0
- package/src/orchestration/coordination/semaphore.ts +280 -0
- package/src/orchestration/dispatching/dispatcher.ts +83 -0
- package/src/orchestration/dispatching/index.ts +2 -0
- package/src/orchestration/dispatching/selector/base-selector.ts +39 -0
- package/src/orchestration/dispatching/selector/down-count-selector.ts +119 -0
- package/src/orchestration/dispatching/selector/index.ts +2 -0
- package/src/orchestration/index.ts +3 -0
- package/src/orchestration/scheduling/index.ts +2 -0
- package/src/orchestration/scheduling/scheduler.ts +103 -0
- package/src/orchestration/scheduling/task.ts +32 -0
- package/src/random/README.md +56 -86
- package/src/random/base.ts +66 -0
- package/src/random/index.ts +5 -1
- package/src/random/random-boolean.ts +40 -0
- package/src/random/random-integer.ts +60 -0
- package/src/random/random-number.ts +72 -0
- package/src/random/random-string.ts +66 -0
- package/src/reactor/README.md +4 -0
- package/src/reactor/reactor-core/primitive.ts +9 -9
- package/src/reactor/reactor-core/reactive-system.ts +5 -5
- package/src/request/README.md +108 -0
- package/src/request/fetch/base.ts +108 -0
- package/src/request/fetch/browser.ts +285 -0
- package/src/request/fetch/general.ts +20 -0
- package/src/request/fetch/index.ts +4 -0
- package/src/request/fetch/nodejs.ts +285 -0
- package/src/request/index.ts +2 -0
- package/src/request/request/base.ts +250 -0
- package/src/request/request/general.ts +64 -0
- package/src/request/request/index.ts +3 -0
- package/src/request/request/resource.ts +68 -0
- package/src/result/README.md +4 -0
- package/src/result/controller.ts +54 -0
- package/src/result/either.ts +193 -0
- package/src/result/index.ts +2 -0
- package/src/route/README.md +105 -0
- package/src/route/adapter/browser.ts +122 -0
- package/src/route/adapter/driver.ts +56 -0
- package/src/route/adapter/index.ts +2 -0
- package/src/route/index.ts +3 -0
- package/src/route/router/index.ts +2 -0
- package/src/route/router/route.ts +630 -0
- package/src/route/router/router.ts +1642 -0
- package/src/route/uri/hash.ts +308 -0
- package/src/route/uri/index.ts +7 -0
- package/src/route/uri/pathname.ts +376 -0
- package/src/route/uri/search.ts +413 -0
- package/src/singleton/README.md +79 -0
- package/src/singleton/factory.ts +55 -0
- package/src/singleton/index.ts +2 -0
- package/src/singleton/manager.ts +204 -0
- package/src/socket/README.md +105 -0
- package/src/socket/client/index.ts +2 -0
- package/src/socket/client/socket-unit.ts +660 -0
- package/src/socket/client/socket.ts +203 -0
- package/src/socket/common/index.ts +2 -0
- package/src/socket/common/socket-unit-common.ts +23 -0
- package/src/socket/common/socket-unit-heartbeat.ts +427 -0
- package/src/socket/index.ts +3 -0
- package/src/socket/server/index.ts +3 -0
- package/src/socket/server/server.ts +183 -0
- package/src/socket/server/socket-unit.ts +449 -0
- package/src/socket/server/socket.ts +264 -0
- package/src/storage/README.md +107 -0
- package/src/storage/index.ts +1 -0
- package/src/storage/table.ts +449 -0
- package/src/timer/README.md +86 -0
- package/src/timer/expiration/expiration-manager.ts +594 -0
- package/src/timer/expiration/index.ts +3 -0
- package/src/timer/expiration/min-heap.ts +208 -0
- package/src/timer/expiration/remaining-manager.ts +241 -0
- package/src/timer/index.ts +1 -0
- package/src/tube/README.md +99 -0
- package/src/tube/helper.ts +138 -0
- package/src/tube/index.ts +2 -0
- package/src/tube/tube.ts +880 -0
- package/src/type/README.md +54 -307
- package/src/type/class.ts +2 -2
- package/src/type/index.ts +14 -14
- package/src/type/is.ts +265 -2
- package/src/type/object.ts +37 -0
- package/src/type/string.ts +7 -2
- package/src/type/tuple.ts +6 -6
- package/src/type/union.ts +16 -0
- package/src/web/README.md +77 -0
- package/src/web/capture.ts +35 -0
- package/src/web/clipboard.ts +97 -0
- package/src/web/dom.ts +117 -0
- package/src/web/download.ts +16 -0
- package/src/web/event.ts +46 -0
- package/src/web/index.ts +10 -0
- package/src/web/local-storage.ts +113 -0
- package/src/web/location.ts +28 -0
- package/src/web/permission.ts +172 -0
- package/src/web/script-loader.ts +432 -0
- package/src/weixin/README.md +1 -0
- package/src/weixin/index.ts +2 -0
- package/src/weixin/official-account/authorization.ts +159 -0
- package/src/weixin/official-account/index.ts +2 -0
- package/src/weixin/official-account/js-api.ts +134 -0
- package/src/weixin/open/index.ts +1 -0
- package/src/weixin/open/oauth2.ts +133 -0
- package/tests/unit/abort/abort-manager.spec.ts +225 -0
- package/tests/unit/abort/abort-signal-listener-manager.spec.ts +62 -0
- package/tests/unit/ai/ai.spec.ts +85 -0
- package/tests/unit/aio/content.spec.ts +105 -0
- package/tests/unit/aio/json.spec.ts +147 -0
- package/tests/unit/aio/prompt.spec.ts +111 -0
- package/tests/unit/basic/array.spec.ts +1 -1
- package/tests/unit/basic/error.spec.ts +16 -4
- package/tests/unit/basic/schedule.spec.ts +74 -0
- package/tests/unit/basic/stream.spec.ts +91 -38
- package/tests/unit/basic/string.spec.ts +0 -9
- package/tests/unit/color/rgb/analyze.spec.ts +110 -0
- package/tests/unit/color/rgb/construct.spec.ts +56 -0
- package/tests/unit/color/rgb/convert.spec.ts +60 -0
- package/tests/unit/color/rgb/derive.spec.ts +103 -0
- package/tests/unit/color/rgb/parse.spec.ts +66 -0
- package/tests/unit/color/rgb/serialize.spec.ts +46 -0
- package/tests/unit/color/xyz/analyze.spec.ts +33 -0
- package/tests/unit/color/xyz/construct.spec.ts +10 -0
- package/tests/unit/color/xyz/convert.spec.ts +18 -0
- package/tests/unit/credential/api-key.spec.ts +37 -0
- package/tests/unit/credential/bearer.spec.ts +23 -0
- package/tests/unit/credential/json-web-token.spec.ts +23 -0
- package/tests/unit/credential/password.spec.ts +41 -0
- package/tests/unit/cron/cron.spec.ts +84 -0
- package/tests/unit/css/class.spec.ts +157 -0
- package/tests/unit/environment/basic.spec.ts +20 -0
- package/tests/unit/environment/device.spec.ts +146 -0
- package/tests/unit/environment/feature.spec.ts +388 -0
- package/tests/unit/environment/geo.spec.ts +111 -0
- package/tests/unit/environment/runtime.spec.ts +364 -0
- package/tests/unit/environment/snapshot.spec.ts +4 -0
- package/tests/unit/environment/variable.spec.ts +190 -0
- package/tests/unit/event/class-event-proxy.spec.ts +225 -0
- package/tests/unit/event/event-manager.spec.ts +246 -0
- package/tests/unit/event/instance-event-proxy.spec.ts +187 -0
- package/tests/unit/exception/browser.spec.ts +213 -0
- package/tests/unit/exception/nodejs.spec.ts +144 -0
- package/tests/unit/exception/normalize.spec.ts +57 -0
- package/tests/unit/form/inputor-controller/base.spec.ts +458 -0
- package/tests/unit/form/inputor-controller/boolean.spec.ts +30 -0
- package/tests/unit/form/inputor-controller/file.spec.ts +27 -0
- package/tests/unit/form/inputor-controller/form.spec.ts +120 -0
- package/tests/unit/form/inputor-controller/helper.spec.ts +67 -0
- package/tests/unit/form/inputor-controller/multi-select.spec.ts +34 -0
- package/tests/unit/form/inputor-controller/number.spec.ts +36 -0
- package/tests/unit/form/inputor-controller/select.spec.ts +49 -0
- package/tests/unit/form/inputor-controller/text.spec.ts +34 -0
- package/tests/unit/http/api/api-core-host.spec.ts +207 -0
- package/tests/unit/http/api/api-schema.spec.ts +120 -0
- package/tests/unit/http/api/api-server.spec.ts +363 -0
- package/tests/unit/http/api/api-test.spec.ts +117 -0
- package/tests/unit/http/api/api.spec.ts +121 -0
- package/tests/unit/http/api-adapter/node-http.spec.ts +191 -0
- package/tests/unit/identifier/id.spec.ts +71 -0
- package/tests/unit/identifier/uuid.spec.ts +85 -0
- package/tests/unit/json/repair.spec.ts +11 -0
- package/tests/unit/log/log-emitter.spec.ts +33 -0
- package/tests/unit/log/log-scheduler.spec.ts +40 -0
- package/tests/unit/log/log-type.spec.ts +7 -0
- package/tests/unit/log/logger.spec.ts +237 -0
- package/tests/unit/openai/openai.spec.ts +64 -0
- package/tests/unit/orchestration/coordination/barrier.spec.ts +96 -0
- package/tests/unit/orchestration/coordination/count-down-latch.spec.ts +63 -0
- package/tests/unit/orchestration/coordination/errors.spec.ts +29 -0
- package/tests/unit/orchestration/coordination/keyed-lock.spec.ts +109 -0
- package/tests/unit/orchestration/coordination/mutex.spec.ts +132 -0
- package/tests/unit/orchestration/coordination/permit.spec.ts +43 -0
- package/tests/unit/orchestration/coordination/read-write-lock.spec.ts +154 -0
- package/tests/unit/orchestration/coordination/semaphore.spec.ts +135 -0
- package/tests/unit/orchestration/dispatching/dispatcher.spec.ts +41 -0
- package/tests/unit/orchestration/dispatching/selector/down-count-selector.spec.ts +81 -0
- package/tests/unit/orchestration/scheduling/scheduler.spec.ts +103 -0
- package/tests/unit/random/base.spec.ts +58 -0
- package/tests/unit/random/random-boolean.spec.ts +25 -0
- package/tests/unit/random/random-integer.spec.ts +32 -0
- package/tests/unit/random/random-number.spec.ts +33 -0
- package/tests/unit/random/random-string.spec.ts +22 -0
- package/tests/unit/reactor/alien-signals-effect.spec.ts +11 -10
- package/tests/unit/reactor/preact-signal.spec.ts +1 -2
- package/tests/unit/request/fetch/browser.spec.ts +222 -0
- package/tests/unit/request/fetch/general.spec.ts +43 -0
- package/tests/unit/request/fetch/nodejs.spec.ts +225 -0
- package/tests/unit/request/request/base.spec.ts +385 -0
- package/tests/unit/request/request/general.spec.ts +161 -0
- package/tests/unit/route/router/route.spec.ts +431 -0
- package/tests/unit/route/router/router.spec.ts +407 -0
- package/tests/unit/route/uri/hash.spec.ts +72 -0
- package/tests/unit/route/uri/pathname.spec.ts +147 -0
- package/tests/unit/route/uri/search.spec.ts +107 -0
- package/tests/unit/singleton/singleton.spec.ts +49 -0
- package/tests/unit/socket/client.spec.ts +208 -0
- package/tests/unit/socket/server.spec.ts +135 -0
- package/tests/unit/socket/socket-unit-heartbeat.spec.ts +214 -0
- package/tests/unit/storage/table.spec.ts +620 -0
- package/tests/unit/timer/expiration/expiration-manager.spec.ts +464 -0
- package/tests/unit/timer/expiration/min-heap.spec.ts +71 -0
- package/tests/unit/timer/expiration/remaining-manager.spec.ts +234 -0
- package/tests/unit/tube/helper.spec.ts +139 -0
- package/tests/unit/tube/tube.spec.ts +501 -0
- package/.oxlintrc.json +0 -5
- package/src/random/uuid.ts +0 -103
- package/tests/unit/random/uuid.spec.ts +0 -37
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { LogRecord } from "./log-record.ts"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Describe options consumed by log emitters.
|
|
5
|
+
*/
|
|
6
|
+
export interface LogEmitterOptions extends Omit<LogRecord, "type"> {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Define the base emitter contract for dispatching formatted logs.
|
|
10
|
+
*/
|
|
11
|
+
export abstract class LogEmitter {
|
|
12
|
+
readonly tags: string[]
|
|
13
|
+
readonly messages: unknown[]
|
|
14
|
+
|
|
15
|
+
readonly formattedMessages: string[]
|
|
16
|
+
|
|
17
|
+
constructor(options: LogEmitterOptions) {
|
|
18
|
+
this.tags = options.tags ?? []
|
|
19
|
+
this.messages = options.messages ?? []
|
|
20
|
+
|
|
21
|
+
this.formattedMessages = []
|
|
22
|
+
this.formattedMessages.push(this.tags.map(tag => `[${tag}]`).join(""))
|
|
23
|
+
this.formattedMessages.push(this.messages.map(message => String(message)).join(" "))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
abstract emit(): void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Emit `log` records via `console.log`.
|
|
31
|
+
*/
|
|
32
|
+
export class ConsoleLogLogEmitter extends LogEmitter {
|
|
33
|
+
emit(): void {
|
|
34
|
+
console.log(this.formattedMessages.join(" "))
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Emit `info` records via `console.info`.
|
|
40
|
+
*/
|
|
41
|
+
export class ConsoleInfoLogEmitter extends LogEmitter {
|
|
42
|
+
emit(): void {
|
|
43
|
+
console.info(this.formattedMessages.join(" "))
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Emit `warn` records via `console.warn`.
|
|
49
|
+
*/
|
|
50
|
+
export class ConsoleWarnLogEmitter extends LogEmitter {
|
|
51
|
+
emit(): void {
|
|
52
|
+
console.warn(this.formattedMessages.join(" "))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Emit `error` records via `console.error`.
|
|
58
|
+
*/
|
|
59
|
+
export class ConsoleErrorLogEmitter extends LogEmitter {
|
|
60
|
+
emit(): void {
|
|
61
|
+
console.error(this.formattedMessages.join(" "))
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Emit `debug` records via `console.debug`.
|
|
67
|
+
*/
|
|
68
|
+
export class ConsoleDebugLogEmitter extends LogEmitter {
|
|
69
|
+
emit(): void {
|
|
70
|
+
console.debug(this.formattedMessages.join(" "))
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { LogRecord } from "./log-record.ts"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Describe a schedulable log emission task.
|
|
5
|
+
*/
|
|
6
|
+
export interface LogTask {
|
|
7
|
+
record: LogRecord
|
|
8
|
+
emit: () => void
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Represent supported scheduling strategies.
|
|
12
|
+
*/
|
|
13
|
+
export type LogSchedulerStrategy = "immediate"
|
|
14
|
+
/**
|
|
15
|
+
* Describe options used to configure a log scheduler.
|
|
16
|
+
*/
|
|
17
|
+
export interface LogSchedulerOptions {
|
|
18
|
+
strategy: LogSchedulerStrategy
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Queue and dispatch log tasks based on scheduling strategy.
|
|
22
|
+
*/
|
|
23
|
+
export class LogScheduler {
|
|
24
|
+
protected strategy: LogSchedulerStrategy
|
|
25
|
+
|
|
26
|
+
protected taskQueue: LogTask[][]
|
|
27
|
+
|
|
28
|
+
constructor(options: LogSchedulerOptions) {
|
|
29
|
+
this.strategy = options.strategy
|
|
30
|
+
|
|
31
|
+
this.taskQueue = []
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Check if there are any tasks in the queue.
|
|
36
|
+
*/
|
|
37
|
+
hasTasks(): boolean {
|
|
38
|
+
return this.taskQueue.length !== 0
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Enqueue tasks and run immediately when strategy requires.
|
|
43
|
+
*/
|
|
44
|
+
enqueue(task: LogTask[]): void {
|
|
45
|
+
this.taskQueue.push(task)
|
|
46
|
+
if (this.strategy === "immediate") {
|
|
47
|
+
this.run()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Flush queued tasks in insertion order.
|
|
53
|
+
*/
|
|
54
|
+
run(): void {
|
|
55
|
+
const tasksToRun = [...this.taskQueue].flat()
|
|
56
|
+
this.taskQueue = []
|
|
57
|
+
for (const task of tasksToRun) {
|
|
58
|
+
task.emit()
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Get the singleton global `LogScheduler` instance.
|
|
65
|
+
*/
|
|
66
|
+
export const getGlobalLogScheduler: () => LogScheduler = (
|
|
67
|
+
() => {
|
|
68
|
+
let instance: LogScheduler | undefined = undefined
|
|
69
|
+
return (): LogScheduler => {
|
|
70
|
+
instance = instance ?? new LogScheduler({ strategy: "immediate" })
|
|
71
|
+
return instance
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
)()
|
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
import { generateUuidV4FromUrl } from "#Source/identifier/index.ts"
|
|
2
|
+
import { getGlobalLogScheduler } from "./log-scheduler.ts"
|
|
3
|
+
|
|
4
|
+
import type { LogRecord } from "./log-record.ts"
|
|
5
|
+
import type { LogTask } from "./log-scheduler.ts"
|
|
6
|
+
import type { LogType } from "./log-type.ts"
|
|
7
|
+
import {
|
|
8
|
+
ConsoleDebugLogEmitter,
|
|
9
|
+
ConsoleErrorLogEmitter,
|
|
10
|
+
ConsoleInfoLogEmitter,
|
|
11
|
+
ConsoleLogLogEmitter,
|
|
12
|
+
ConsoleWarnLogEmitter,
|
|
13
|
+
} from "./log-emitter.ts"
|
|
14
|
+
import type { LogEmitter, LogEmitterOptions } from "./log-emitter.ts"
|
|
15
|
+
|
|
16
|
+
const globalLogScheduler = getGlobalLogScheduler()
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Describe an object that exposes a `Logger` instance.
|
|
20
|
+
*/
|
|
21
|
+
export interface LoggerFriendly {
|
|
22
|
+
logger: Logger
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Describe options that may provide an existing `Logger`.
|
|
26
|
+
*/
|
|
27
|
+
export interface LoggerFriendlyOptions {
|
|
28
|
+
logger?: Logger | undefined
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Describe an emitter registration for a specific log type.
|
|
33
|
+
*/
|
|
34
|
+
export interface LogEmitterItem {
|
|
35
|
+
logType: LogType
|
|
36
|
+
// oxlint-disable-next-line no-explicit-any
|
|
37
|
+
LogEmitter: new (...args: any[]) => LogEmitter
|
|
38
|
+
injectOptions?: ((options: LogEmitterOptions) => LogEmitterOptions) | undefined
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Define the default console-based emitters.
|
|
42
|
+
*/
|
|
43
|
+
const DEFAULT_CONSOLE_LOG_EMITTER_ITEMS: LogEmitterItem[] = [
|
|
44
|
+
{
|
|
45
|
+
logType: "log",
|
|
46
|
+
LogEmitter: ConsoleLogLogEmitter,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
logType: "info",
|
|
50
|
+
LogEmitter: ConsoleInfoLogEmitter,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
logType: "warn",
|
|
54
|
+
LogEmitter: ConsoleWarnLogEmitter,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
logType: "error",
|
|
58
|
+
LogEmitter: ConsoleErrorLogEmitter,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
logType: "debug",
|
|
62
|
+
LogEmitter: ConsoleDebugLogEmitter,
|
|
63
|
+
},
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Describe runtime logger configuration values.
|
|
68
|
+
*/
|
|
69
|
+
export interface LoggerConfigs {
|
|
70
|
+
enabled: boolean
|
|
71
|
+
autoSend: boolean
|
|
72
|
+
filter: ((logRecord: LogRecord) => boolean)
|
|
73
|
+
emitters: LogEmitterItem[]
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Describe options used to construct a `Logger`.
|
|
77
|
+
*/
|
|
78
|
+
export interface LoggerOptions {
|
|
79
|
+
name?: string | undefined
|
|
80
|
+
parent?: Logger | undefined
|
|
81
|
+
configs?: Partial<LoggerConfigs> | undefined
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 表示支持层级继承、标签管理与延迟发送的日志记录器。
|
|
85
|
+
*
|
|
86
|
+
* 规范:
|
|
87
|
+
* - 初始配置的优先级为 parentConfigs -> configs -> 默认值。
|
|
88
|
+
* - 当 parent 为 undefined 时,parentConfigs 也应该是 undefined。
|
|
89
|
+
* - 更新 parent 时,parentConfigs 也应该同步更新。
|
|
90
|
+
* - 作为 parent 修改自己的 configs 时,不会影响 child 的 configs。
|
|
91
|
+
* - 作为 child 可以独立修改自己的 configs,也可以将 parentConfigs 应用到自己的 configs。
|
|
92
|
+
*/
|
|
93
|
+
export class Logger implements Disposable {
|
|
94
|
+
/**
|
|
95
|
+
* 从选项中解析 logger;如果未提供,则基于全局 logger 派生一个新 logger。
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```
|
|
99
|
+
* // Expect: example1 === customLogger
|
|
100
|
+
* const customLogger = new Logger({ name: "Custom" })
|
|
101
|
+
* const example1 = Logger.fromOptions({ logger: customLogger })
|
|
102
|
+
*
|
|
103
|
+
* // Expect: example2 !== globalLogger
|
|
104
|
+
* // Expect: example2.hasParent() === true
|
|
105
|
+
* const globalLogger = getGlobalLogger()
|
|
106
|
+
* const example2 = Logger.fromOptions({})
|
|
107
|
+
*
|
|
108
|
+
* class CustomClass implements LoggerFriendly {
|
|
109
|
+
* logger: Logger
|
|
110
|
+
*
|
|
111
|
+
* constructor(options: LoggerFriendlyOptions) {
|
|
112
|
+
* this.logger = Logger.fromOptions(options)
|
|
113
|
+
* }
|
|
114
|
+
* }
|
|
115
|
+
*
|
|
116
|
+
* // Expect: example3.logger instanceof Logger
|
|
117
|
+
* const example3 = new CustomClass({ logger: customLogger })
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
static fromOptions(options: LoggerFriendlyOptions): Logger {
|
|
121
|
+
if (options.logger !== undefined) {
|
|
122
|
+
return options.logger
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const parent = getGlobalLogger()
|
|
126
|
+
const logger = Logger.derive(parent)
|
|
127
|
+
return logger
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Create a child logger from a parent logger.
|
|
132
|
+
*/
|
|
133
|
+
static derive(parentLogger: Logger): Logger {
|
|
134
|
+
const logger = new Logger({ parent: parentLogger })
|
|
135
|
+
return logger
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
protected defaultName: string
|
|
139
|
+
protected name?: string | undefined
|
|
140
|
+
protected parent?: Logger | undefined
|
|
141
|
+
protected childs: Logger[]
|
|
142
|
+
protected parentConfigs?: LoggerConfigs | undefined
|
|
143
|
+
protected configs: LoggerConfigs
|
|
144
|
+
|
|
145
|
+
protected instanceTags: string[]
|
|
146
|
+
protected sessionTags: string[]
|
|
147
|
+
protected onceTags: string[]
|
|
148
|
+
|
|
149
|
+
private logTasks: LogTask[]
|
|
150
|
+
private cachedLogMethodMap: Map<string, (...messages: unknown[]) => this>
|
|
151
|
+
|
|
152
|
+
constructor(options: LoggerOptions) {
|
|
153
|
+
this.defaultName = "Unnamed"
|
|
154
|
+
this.name = options.name
|
|
155
|
+
this.parent = options.parent
|
|
156
|
+
this.childs = []
|
|
157
|
+
const parentConfigs = options.parent?.getConfigs()
|
|
158
|
+
const configs = options.configs
|
|
159
|
+
this.parentConfigs = parentConfigs
|
|
160
|
+
this.configs = {
|
|
161
|
+
enabled: parentConfigs?.enabled ?? configs?.enabled ?? true,
|
|
162
|
+
autoSend: parentConfigs?.autoSend ?? configs?.autoSend ?? true,
|
|
163
|
+
filter: parentConfigs?.filter ?? configs?.filter ?? ((): boolean => true),
|
|
164
|
+
emitters: parentConfigs?.emitters ?? configs?.emitters ?? DEFAULT_CONSOLE_LOG_EMITTER_ITEMS
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
this.instanceTags = []
|
|
168
|
+
this.sessionTags = []
|
|
169
|
+
this.onceTags = []
|
|
170
|
+
|
|
171
|
+
this.logTasks = []
|
|
172
|
+
this.cachedLogMethodMap = new Map()
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Set the default name if the current name is empty,
|
|
177
|
+
* and return the logger for chaining.
|
|
178
|
+
*/
|
|
179
|
+
setDefaultName(name: string): this {
|
|
180
|
+
this.defaultName = name
|
|
181
|
+
return this
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get the logger display name.
|
|
186
|
+
*/
|
|
187
|
+
getName(): string {
|
|
188
|
+
return this.name ?? this.defaultName
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Set the logger display name.
|
|
193
|
+
*/
|
|
194
|
+
setName(name: string | undefined): this {
|
|
195
|
+
this.name = name
|
|
196
|
+
return this
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Check whether the logger currently has a parent.
|
|
201
|
+
*/
|
|
202
|
+
hasParent(): boolean {
|
|
203
|
+
return this.parent !== undefined
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Set or clear the parent logger.
|
|
208
|
+
*/
|
|
209
|
+
setParent(parentLogger?: Logger | undefined): this {
|
|
210
|
+
this.parent = parentLogger
|
|
211
|
+
this.parentConfigs = parentLogger?.getConfigs()
|
|
212
|
+
return this
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Get merged effective configs from parent and local overrides.
|
|
217
|
+
*/
|
|
218
|
+
getConfigs(): LoggerConfigs {
|
|
219
|
+
return { ...this.parentConfigs, ...this.configs }
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Update local configs and refresh inherited configs on child loggers.
|
|
224
|
+
*/
|
|
225
|
+
setConfigs(configs: Partial<LoggerConfigs>): this {
|
|
226
|
+
this.configs = { ...this.getConfigs(), ...configs }
|
|
227
|
+
for (const child of this.childs) {
|
|
228
|
+
child.setParent(this)
|
|
229
|
+
}
|
|
230
|
+
return this
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Apply current parent configs onto local configs.
|
|
235
|
+
*/
|
|
236
|
+
useParentConfigs(): this {
|
|
237
|
+
if (this.parentConfigs !== undefined) {
|
|
238
|
+
this.setConfigs(this.parentConfigs)
|
|
239
|
+
}
|
|
240
|
+
return this
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Get all configured emitter registrations.
|
|
245
|
+
*/
|
|
246
|
+
getAllLogEmitters(): LogEmitterItem[] {
|
|
247
|
+
const emitters = this.getConfigs().emitters
|
|
248
|
+
return emitters
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Get emitter registrations for a specific log type.
|
|
253
|
+
*/
|
|
254
|
+
getLogEmitters(logType: LogType): LogEmitterItem[] {
|
|
255
|
+
const emitters = this.getConfigs().emitters
|
|
256
|
+
const filteredEmitters = emitters.filter(item => item.logType === logType)
|
|
257
|
+
return filteredEmitters
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* 支持为同一类型的 Log 添加多个 LogEmitter。
|
|
262
|
+
*/
|
|
263
|
+
addLogEmitters(logEmitters: LogEmitterItem[]): this {
|
|
264
|
+
const newEmitters = [...this.getConfigs().emitters]
|
|
265
|
+
for (const item of logEmitters) {
|
|
266
|
+
if (!newEmitters.some((e) => e.logType === item.logType && e.LogEmitter === item.LogEmitter)) {
|
|
267
|
+
newEmitters.push(item)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
this.setConfigs({
|
|
271
|
+
emitters: newEmitters
|
|
272
|
+
})
|
|
273
|
+
return this
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Remove matched emitter registrations.
|
|
278
|
+
*/
|
|
279
|
+
removeLogEmitters(logEmitters: LogEmitterItem[]): this {
|
|
280
|
+
const emitters = this.getConfigs().emitters
|
|
281
|
+
const remainingEmitters = emitters.filter((item) => {
|
|
282
|
+
return !logEmitters.some((e) => e.logType === item.logType && e.LogEmitter === item.LogEmitter)
|
|
283
|
+
})
|
|
284
|
+
this.setConfigs({
|
|
285
|
+
emitters: remainingEmitters
|
|
286
|
+
})
|
|
287
|
+
return this
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Invoke all emitters that match the record log type.
|
|
292
|
+
*/
|
|
293
|
+
invokeLogEmitter(record: LogRecord): void {
|
|
294
|
+
const { type } = record
|
|
295
|
+
if (type === undefined) {
|
|
296
|
+
return
|
|
297
|
+
}
|
|
298
|
+
const logEmitterList = this.getLogEmitters(type)
|
|
299
|
+
if (logEmitterList.length === 0) {
|
|
300
|
+
return
|
|
301
|
+
}
|
|
302
|
+
logEmitterList.forEach((item) => {
|
|
303
|
+
const injectOptions = item.injectOptions ?? (<T>(v: T): T => v)
|
|
304
|
+
const LogEmitter = item.LogEmitter
|
|
305
|
+
const logEmitter = new LogEmitter(injectOptions(record))
|
|
306
|
+
logEmitter.emit()
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Get full hierarchical name tags from root to current logger.
|
|
312
|
+
*/
|
|
313
|
+
getNameTags(): string[] {
|
|
314
|
+
const names = [...this.parent?.getNameTags() ?? [], this.getName()]
|
|
315
|
+
return names
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Add persistent instance tags.
|
|
320
|
+
*/
|
|
321
|
+
addInstanceTags(tags: string[]): this {
|
|
322
|
+
this.instanceTags.push(...tags)
|
|
323
|
+
return this
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Remove matched instance tags.
|
|
328
|
+
*/
|
|
329
|
+
removeInstanceTags(tags: string[]): this {
|
|
330
|
+
this.instanceTags = this.instanceTags.filter(tag => !tags.includes(tag))
|
|
331
|
+
return this
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Get current instance tags.
|
|
336
|
+
*/
|
|
337
|
+
getInstanceTags(): string[] {
|
|
338
|
+
return this.instanceTags
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Clear all instance tags.
|
|
343
|
+
*/
|
|
344
|
+
clearInstanceTags(): this {
|
|
345
|
+
this.instanceTags = []
|
|
346
|
+
return this
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Add session tags used until `tagEnd` is called.
|
|
351
|
+
*/
|
|
352
|
+
addSessionTags(tags: string[]): this {
|
|
353
|
+
this.sessionTags.push(...tags)
|
|
354
|
+
return this
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Remove matched session tags.
|
|
359
|
+
*/
|
|
360
|
+
removeSessionTags(tags: string[]): this {
|
|
361
|
+
this.sessionTags = this.sessionTags.filter(tag => !tags.includes(tag))
|
|
362
|
+
return this
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Get current session tags.
|
|
367
|
+
*/
|
|
368
|
+
getSessionTags(): string[] {
|
|
369
|
+
return this.sessionTags
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Clear all session tags.
|
|
374
|
+
*/
|
|
375
|
+
clearSessionTags(): this {
|
|
376
|
+
this.sessionTags = []
|
|
377
|
+
return this
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Start and automatically end a session tag scope on dispose.
|
|
382
|
+
*/
|
|
383
|
+
autoTag(tags: string[]): Disposable {
|
|
384
|
+
this.tagStart(tags)
|
|
385
|
+
return {
|
|
386
|
+
[Symbol.dispose]: (): void => {
|
|
387
|
+
this.tagEnd()
|
|
388
|
+
},
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Start a session tag scope.
|
|
394
|
+
*/
|
|
395
|
+
tagStart(tags: string[]): this {
|
|
396
|
+
this.addSessionTags(tags)
|
|
397
|
+
return this
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* End the current session tag scope.
|
|
402
|
+
*/
|
|
403
|
+
tagEnd(): this {
|
|
404
|
+
this.clearSessionTags()
|
|
405
|
+
return this
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Add one-shot tags consumed by the next log call.
|
|
410
|
+
*/
|
|
411
|
+
addOnceTags(tags: string[]): this {
|
|
412
|
+
this.onceTags.push(...tags)
|
|
413
|
+
return this
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Get current one-shot tags.
|
|
418
|
+
*/
|
|
419
|
+
getOnceTags(): string[] {
|
|
420
|
+
return this.onceTags
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Clear all one-shot tags.
|
|
425
|
+
*/
|
|
426
|
+
clearOnceTags(): this {
|
|
427
|
+
this.onceTags = []
|
|
428
|
+
return this
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Build and cache a log method bound to type and prefix.
|
|
433
|
+
*/
|
|
434
|
+
private makeLogMethod(logType: LogType, prefix: string): ((...args: unknown[]) => this) {
|
|
435
|
+
const cachedLogMethodKey = `${logType}-${prefix}`
|
|
436
|
+
const cachedLogMethod = this.cachedLogMethodMap.get(cachedLogMethodKey)
|
|
437
|
+
if (cachedLogMethod !== undefined) {
|
|
438
|
+
return cachedLogMethod
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const newMethod = (...messages: unknown[]): this => {
|
|
442
|
+
const configs = this.getConfigs()
|
|
443
|
+
if (configs.enabled === false) {
|
|
444
|
+
return this
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const tags = [
|
|
448
|
+
prefix,
|
|
449
|
+
...this.getNameTags(),
|
|
450
|
+
...this.getInstanceTags(),
|
|
451
|
+
...this.getSessionTags(),
|
|
452
|
+
...this.getOnceTags()
|
|
453
|
+
]
|
|
454
|
+
const logRecord: LogRecord = {
|
|
455
|
+
type: logType,
|
|
456
|
+
tags: tags,
|
|
457
|
+
messages,
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// oxlint-disable-next-line no-array-callback-reference
|
|
461
|
+
if (configs.filter(logRecord) === false) {
|
|
462
|
+
return this
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
this.logTasks.push({
|
|
466
|
+
record: logRecord,
|
|
467
|
+
emit: () => {
|
|
468
|
+
this.invokeLogEmitter(logRecord)
|
|
469
|
+
}
|
|
470
|
+
})
|
|
471
|
+
if (configs.autoSend === true) {
|
|
472
|
+
this.send()
|
|
473
|
+
}
|
|
474
|
+
this.clearOnceTags()
|
|
475
|
+
return this
|
|
476
|
+
}
|
|
477
|
+
this.cachedLogMethodMap.set(cachedLogMethodKey, newMethod)
|
|
478
|
+
|
|
479
|
+
return newMethod
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Queue a `log` level record.
|
|
484
|
+
*/
|
|
485
|
+
log(...messages: unknown[]): this {
|
|
486
|
+
return this.makeLogMethod("log", "🟢")(...messages)
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Queue an `info` level record.
|
|
491
|
+
*/
|
|
492
|
+
info(...messages: unknown[]): this {
|
|
493
|
+
return this.makeLogMethod("info", "🔵")(...messages)
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Queue a `warn` level record.
|
|
498
|
+
*/
|
|
499
|
+
warn(...messages: unknown[]): this {
|
|
500
|
+
return this.makeLogMethod("warn", "🟡")(...messages)
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Queue an `error` level record.
|
|
505
|
+
*/
|
|
506
|
+
error(...messages: unknown[]): this {
|
|
507
|
+
return this.makeLogMethod("error", "🔴")(...messages)
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Queue a `debug` level record.
|
|
512
|
+
*/
|
|
513
|
+
debug(...messages: unknown[]): this {
|
|
514
|
+
return this.makeLogMethod("debug", "🟤")(...messages)
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Create a child logger configured for manual batched sending.
|
|
519
|
+
*/
|
|
520
|
+
batch(id?: string | undefined): Logger {
|
|
521
|
+
const logger = Logger.derive(this)
|
|
522
|
+
logger.setConfigs({ autoSend: false })
|
|
523
|
+
logger.addInstanceTags([id ?? generateUuidV4FromUrl()])
|
|
524
|
+
return logger
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Flush queued records to the global scheduler.
|
|
529
|
+
*/
|
|
530
|
+
send(): void {
|
|
531
|
+
globalLogScheduler.enqueue(this.logTasks)
|
|
532
|
+
this.logTasks = []
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Flush queued records when used with `using` disposal.
|
|
537
|
+
*/
|
|
538
|
+
[Symbol.dispose](): void {
|
|
539
|
+
this.send()
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Get the singleton global `Logger` instance.
|
|
545
|
+
*/
|
|
546
|
+
export const getGlobalLogger: () => Logger = (
|
|
547
|
+
() => {
|
|
548
|
+
let instance: Logger | undefined = undefined
|
|
549
|
+
return (): Logger => {
|
|
550
|
+
instance = instance ?? new Logger({ name: "GlobalLogger" })
|
|
551
|
+
return instance
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
)()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Openai
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./openai.ts"
|