-
Notifications
You must be signed in to change notification settings - Fork 0
traits.Interface.DebuggableTrait
@zenstone/ts-utils / traits / DebuggableTrait
Defined in: src/traits/debuggable.ts:74
createDebuggableTrait 返回的 trait 接口,供 interface 声明合并使用。
// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: implTraits guarantees runtime implementation
class MyService { ... }
implTraits(MyService, createDebuggableTrait({ name: 'MyService', color: 'color: #6bcb77' }))
// biome-ignore lint/correctness/noUnusedVariables: trait type extension via implTraits
interface MyService extends DebuggableTrait {}Settings extends DebugSettings = DebugSettings
optionaldebugConfig?:Partial<DebugConfiguration>
Defined in: src/traits/debuggable.ts:78
初始化配置,挂载在原型上,所有实例共享
optionaldebugSettings?:Partial<Settings>
Defined in: src/traits/debuggable.ts:80
运行期调试开关,setDebug() 后成为实例自有属性
debug(
scope, ...args):this
Defined in: src/traits/debuggable.ts:121
在 shouldDebug(scope) 为 true 时输出调试信息,否则静默返回。
输出格式(默认):[时间戳] [name] [scope] ...args
颜色和格式可通过 DebugConfiguration 定制。
string | Exclude<keyof Settings, "debug"> | null | undefined
当前调试 scope,传 null / undefined 表示无 scope
...unknown[]
要输出的内容
this
setDebug(
debug?):this
Defined in: src/traits/debuggable.ts:90
设置调试开关。
-
setDebug(true)— 开启全局调试 -
setDebug(false)— 关闭全局调试 -
setDebug({ fetch: true })— 仅开启 fetch scope,与已有 settings 合并 -
setDebug()— 无参调用为 no-op
boolean | Partial<Settings>
this
shouldDebug(
scope?):boolean
Defined in: src/traits/debuggable.ts:108
判断指定 scope 是否应输出调试信息。
优先级(由高到低):
-
settings[scope](精确匹配) -
settings[ns](取scope中第一个.前的命名空间) -
settings.debug(全局开关)
string | Exclude<keyof Settings, "debug"> | null
boolean
svc.setDebug({ debug: false, fetch: true })
svc.shouldDebug('fetch') // true — scope 精确匹配
svc.shouldDebug('fetch.request') // true — 继承 fetch 命名空间
svc.shouldDebug('ws') // false — 未配置,回落到 debug: false