UNPKG

miniprogram-logger

Version:

It is used to log and gather statistics of users' behavior.

65 lines 2.09 kB
/// <reference lib="es2015" /> import { ITimer } from "./ITimer"; import { Reporter, BasicLogObject } from "../common/reporter"; export interface PerformanceObject extends BasicLogObject { /** * 操作 */ action?: string; /** * 时间 */ duration?: number; } export declare class ReportAnalytics<T extends PerformanceObject, TValues extends T[keyof T][], TKeys extends (keyof T)[] = (keyof T)[]> extends Reporter<T, TValues, TKeys> implements ITimer { private Id; private readonly Stopwatch; constructor(tableName: string, fields?: TKeys, context?: Partial<T>); /** * 快速记录性能日志 * @param action 操作, * @param duration 耗时单位毫秒 * @param context 其它数据 */ log(action: string, duration: number, ...args: RemoveFisrt2<TValues>): void; /** * 快速记录性能日志 * @param data PerformanceParam */ log(data: T): void; /** * * @param label - 唯一标签,结束时使用同样标签, * @param context - 记录上下文信息,如果未设置action则使用label作为action */ time(label: string, context?: Partial<T>): void; /** * * @param label - 唯一标签,与开始对应 * @param context - 记录上下文信息,如果未设置action则使用label作为action */ timeEnd(label: string, context?: Partial<T>): void; /** * 开始计时 * @param action * @param context * @returns 返回计时ID */ start(action: string, context?: Partial<T>): number; start(data: T): number; /** * 完成计时,并清除计时ID * @param id * @param context */ end(id: number, context?: Partial<T>): boolean; /** * 清除计时 * @param id * @returns 不存在返回false */ remove(id: number | string): boolean; } declare type RemoveFisrt2<T extends any[]> = ((...args: T) => void) extends ((a: any, b: any, ...rest: infer Rest) => void) ? Rest : never; export {}; //# sourceMappingURL=report-analytics.d.ts.map