matrix-js-sdk
Version:
Matrix Client-Server SDK for Javascript
81 lines • 2.7 kB
TypeScript
import loglevel from "loglevel";
/** Logger interface used within the js-sdk codebase */
export interface Logger extends BaseLogger {
/**
* Create a child logger.
*
* @param namespace - name to add to the current logger to generate the child. Some implementations of `Logger`
* use this as a prefix; others use a different mechanism.
*/
getChild(namespace: string): Logger;
}
/** The basic interface for a logger which doesn't support children */
export interface BaseLogger {
/**
* Output trace message to the logger, with stack trace.
*
* @param msg - Data to log.
*/
trace(...msg: any[]): void;
/**
* Output debug message to the logger.
*
* @param msg - Data to log.
*/
debug(...msg: any[]): void;
/**
* Output info message to the logger.
*
* @param msg - Data to log.
*/
info(...msg: any[]): void;
/**
* Output warn message to the logger.
*
* @param msg - Data to log.
*/
warn(...msg: any[]): void;
/**
* Output error message to the logger.
*
* @param msg - Data to log.
*/
error(...msg: any[]): void;
}
/**
* Implementation of {@link Logger} based on `loglevel`.
*
* @deprecated this shouldn't be public; prefer {@link Logger}.
*/
export interface PrefixedLogger extends loglevel.Logger, Logger {
/** @deprecated prefer {@link Logger.getChild} */
withPrefix: (prefix: string) => PrefixedLogger;
/** @deprecated internal property */
prefix: string;
}
/**
* Drop-in replacement for `console` using {@link https://www.npmjs.com/package/loglevel|loglevel}.
* Can be tailored down to specific use cases if needed.
*/
export declare const logger: PrefixedLogger;
/**
* A "span" for grouping related log lines together.
*
* The current implementation just adds the name at the start of each log line.
*
* This offers a lighter-weight alternative to 'child' loggers returned by {@link Logger#getChild}. In particular,
* it's not possible to apply individual filters to the LogSpan such as setting the verbosity level. On the other hand,
* no reference to the LogSpan is retained in the logging framework, so it is safe to make lots of them over the course
* of an application's life and just drop references to them when the job is done.
*/
export declare class LogSpan implements BaseLogger {
private readonly parent;
private readonly name;
constructor(parent: BaseLogger, name: string);
trace(...msg: any[]): void;
debug(...msg: any[]): void;
info(...msg: any[]): void;
warn(...msg: any[]): void;
error(...msg: any[]): void;
}
//# sourceMappingURL=logger.d.ts.map