Tiny logger with limited buffer for universal environments.
Written in Typescript, runs everywhere.
const collectedLogs = [];
// create the logger with limit 200 logs
const logger = new DynaLogger({
bufferLimit: 200,
(log: ILog) => collectedLogs.push(log), // collect all detected logs
});
logger.info('Login Page', 'Success login', {user: userInfo});
logger.error('Login Page', 'login failed', {user: userInfo, error: errorObject});
console.log(logger.logs.length); // consoles 2
const collectedLogs = [];
// create the logger with limit 200 logs
const logger = new DynaLogger({
bufferLimit: 200,
replaceGlobalLogMethods: true, // monitors all console log methods
(log: ILog) => collectedLogs.push(log), // collect all detected logs
});
console.info('Login Page', 'Success login', {user: userInfo});
console.error('Login Page', 'login failed', {user: userInfo, error: errorObject});
console.log(logger.logs.length); // consoles 2
- bufferLimit: number; // (default: 5000) -1 = unlimited, 0 = no buffer, >0 size of buffer
- consoleLogs: boolean;
- consoleInfoLogs: boolean;
- consoleErrorLogs: boolean;
- consoleWarnLogs: boolean;
- consoleDebugLogs: boolean;
- keepLogs: boolean;
- keepInfoLogs: boolean;
- keepErrorLogs: boolean;
- keepWarnLogs: boolean;
- keepDebugLogs: boolean;
- replaceGlobalLogMethods: boolean; // call .destroy(); to restore the real console methods
Consoles a log.
Consoles an info.
Consoles an error.
Consoles a warn.
Consoles a debug.
Pass partial or whole config on runtime to the logger.
Note that replaceGlobalLogMethods
is ignored here, only on constructor this has effect.
Shut's down the logger.
If replaceGlobalLogMethods
is set to true, call destroy()
is restoring the original methods.
{
date: Date;
type: string;
content: any[];
}
This feature replaces the global log methods and captures all the consoles.
You can get them by the onLog
config callback and send them or store them.
This project is compatible with Semver.
- First version
- Typings fix in package.json
- Rename of IConfiguration to ISettings
- ELogTypes enum
- Remove the event emitter, use the
onLog
config callback - New feature: consoles all params as it is and not as string, like the native log methods
- New feature:
replaceGlobalLogMethods
, monitors all the logs of the procees.