@ztimson/momentum
Version:
Client library for momentum
108 lines • 3.33 kB
TypeScript
import { LOG_LEVEL, PathEvent, Unsubscribe } from '@ztimson/utils';
import { PathEventEmitter } from './core';
import { Momentum } from './momentum';
/** Log levels */
export type LogLevel = 'ERROR' | 'WARN' | 'INFO' | 'LOG' | 'DEBUG' | 'NONE';
/** Log */
export type Log<T = any> = {
/** Time log was created */
readonly time?: Date;
/** Log level */
readonly level: LOG_LEVEL;
/** Logged data */
readonly log: any;
/** Log context information */
readonly ctx?: T;
};
/** New Log context */
export type CreateLog = Log<string>;
/** Publish logs to server */
export declare class Logger extends PathEventEmitter {
protected momentum: Momentum;
private static cache;
readonly channel: string;
readonly logLevel: LogLevel;
console: {
debug: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
log: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
info: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
warn: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
error: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
};
logs: Log[];
constructor(momentum: Momentum);
private buildLog;
private create;
/**
* Get available channels
* @return {Promise<string[]>} List of channel names
*/
channels(): Promise<string[]>;
/**
* Clear logs in channel
* @param {string} channel Channel to clear
* @return {Promise<number>} Reruns once complete
*/
delete(channel: string): Promise<number>;
/**
* Read logs from channel
* @param {string} channel Channel name
* @return {Promise<Log[]>} Logs in channel
*/
read(channel: string): Promise<Log[]>;
sync(channel: string, callback?: ((event: PathEvent, value: any) => any) | null, opts?: {
path?: string;
reload?: boolean;
}): Unsubscribe;
/**
* Create debug log
* @param log What you want to log
* @param {string} channel Channel to publish log to
* @return {Promise<void>} Log saved
*/
debug(log: any, channel?: string): void;
/**
* Create regular log
* @param log What you want to log
* @param {string} channel Channel to publish log to
* @return {Promise<void>} Log saved
*/
log(log: any, channel?: string): void;
/**
* Create info log
* @param log What you want to log
* @param {string} channel Channel to publish log to
* @return {Promise<void>} Log saved
*/
info(log: any, channel?: string): void;
/**
* Create warning log
* @param log What you want to log
* @param {string} channel Channel to publish log to
* @return {Promise<void>} Log saved
*/
warn(log: any, channel?: string): void;
/**
* Create error log
* @param log What you want to log
* @param {string} channel Channel to publish log to
* @return {Promise<void>} Log saved
*/
error(log: any, channel?: string): void;
}
//# sourceMappingURL=logger.d.ts.map