UNPKG

core-native

Version:

A lightweight framework based on React Native + Redux + Redux Saga, in strict TypeScript.

78 lines (77 loc) 2.19 kB
import { Exception } from "./Exception"; interface Log { date: Date; result: "OK" | "WARN" | "ERROR"; context: { [key: string]: string; }; info: { [key: string]: string; }; elapsedTime: number; action?: string; errorCode?: string; } /** * If eventLogger config is provided in non-DEV environment * All collected logs will automatically sent to {serverURL} every {sendingFrequency} second * * The request will be PUT to the server in the following format * {events: Log[]} */ export interface LoggerConfig { serverURL: string; sendingFrequency: number; maskedKeywords?: RegExp[]; } export interface Logger { addContext(context: { [key: string]: string | (() => string); }): void; /** * Add a log item, whose result is OK */ info(action: string, info?: { [key: string]: string; }): () => void; /** * Add a log item, whose result is WARN * @errorCode: Naming in upper-case and underscore, e.g: SOME_DATA */ warn(errorCode: string, action?: string, info?: { [key: string]: string; }): () => void; /** * Add a log item, whose result is ERROR * @errorCode: Naming in upper-case and underscore, e.g: SOME_DATA */ error(errorCode: string, action?: string, info?: { [key: string]: string; }): () => void; /** * This function can auto convert to ERROR/WARN level with exception information, according to type */ exception(exception: Exception): () => void; } export declare class LoggerImpl implements Logger { private environmentContext; private logQueue; constructor(); addContext(context: { [key: string]: string | (() => string); }): void; info(action: string, info?: { [key: string]: string; }): () => void; warn(errorCode: string, action?: string, info?: { [key: string]: string; }): () => void; error(errorCode: string, action?: string, info?: { [key: string]: string; }): () => void; exception(exception: Exception): () => void; collect(): Log[]; empty(): void; private appendLog; } export {};