miniprogram-logger
Version:
It is used to log and gather statistics of users' behavior.
70 lines • 2.29 kB
TypeScript
import { ILogger, LogLevel } from "./ILogger";
import { Reporter, BasicLogObject } from "../common/reporter";
export interface LogObject extends BasicLogObject {
/**
* 日志级别
*/
level?: LogLevel;
/**
* 操作
*/
action?: string;
/**
* 内容
*/
content?: any;
}
export declare type LogValues = [LogLevel, string, any];
/**
* 微信上报API
*/
export declare class ReportAnalytics<T extends LogObject, TValues extends T[keyof T][] = LogValues> extends Reporter<T, TValues> implements ILogger {
/**
* 记录日志级别
*/
logLevels: LogLevel[];
/**
* @example
* ```
* new ReportAnalytics<LogObject,[LogLevel,string,any]>('logger',['level', 'action', 'content'])
* ```
* @param tableName - 上报的表名
* @param fields - 字段列表,参数表对应,前三个分别是id,record_time,level对应的字段名称
* @param context - 上下文
*/
constructor(tableName: string, fields?: string[], context?: Partial<T>);
/**
* 上报调试信息
* @param action - 操作
* @param content - 内容
*/
debug(action: TValues[1], content?: TValues[2], ...args: RemoveFirst3<TValues>): void;
debug(context: T): void;
/**
* 上报信息
* @param action - 操作
* @param content - 内容
*/
info(action: TValues[1], content?: TValues[2], ...args: RemoveFirst3<TValues>): void;
info(context: T): void;
/**
* 上报警告信息
* @param action - 操作
* @param content - 内容
*/
warn(action: TValues[1], content?: TValues[2], ...args: RemoveFirst3<TValues>): void;
warn(context: T): void;
/**
* 上报错误信息
* @param action - 操作
* @param content - 内容
*/
error(action: TValues[1], content?: TValues[2], ...args: RemoveFirst3<TValues>): void;
error(context: T): void;
log(level: TValues[0], action: TValues[1], content?: TValues[2], ...args: RemoveFirst3<TValues>): void;
log(context: Partial<T>): void;
private logByLevel;
}
declare type RemoveFirst3<T extends any[]> = ((...args: T) => void) extends ((a: any, b: any, c: any, ...rest: infer Rest) => void) ? Rest : never;
export {};
//# sourceMappingURL=report-analytics.d.ts.map