本文整理匯總了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;
};
},
});
}