本文整理汇总了TypeScript中@kbn/dev-utils.ToolingLog.getWriters方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ToolingLog.getWriters方法的具体用法?TypeScript ToolingLog.getWriters怎么用?TypeScript ToolingLog.getWriters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@kbn/dev-utils.ToolingLog
的用法示例。
在下文中一共展示了ToolingLog.getWriters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createVerboseInstance
export function createVerboseInstance(
log: ToolingLog,
name: string,
instance: { [k: string]: any; [i: number]: any }
) {
if (!log.getWriters().some(l => (l as any).level.flags.verbose)) {
return instance;
}
return new Proxy(instance, {
get(_, prop) {
const value = (instance as any)[prop];
if (typeof value !== 'function' || prop === 'init' || typeof prop === 'symbol') {
return value;
}
return function(this: any, ...args: any[]) {
log.verbose(`${name}.${prop}(${printArgs(args)})`);
log.indent(2);
let result;
try {
result = {
returned: value.apply(this, args),
};
} catch (error) {
result = {
returned: undefined,
thrown: error,
};
}
if (result.hasOwnProperty('thrown')) {
log.indent(-2);
throw result.thrown;
}
const { returned } = result;
if (returned && typeof returned.then === 'function') {
return returned.finally(() => {
log.indent(-2);
});
}
log.indent(-2);
return returned;
};
},
});
}