0.2.0 • Published 10 months ago
@davidsneighbour/debuglogger v0.2.0
debuglogger is a customizable logging wrapper that enhances debugging with log levels, external handlers, and console replacement.
Installation
npm install @davidsneighbour/debugloggerUsage
Importing and Using the Singleton Instance
import { logger } from '@davidsneighbour/debuglogger';
logger.log('This is a log message');
logger.warn('This is a warning');
logger.error('This is an error');Creating a Custom Logger Instance
import debuglogger from '@davidsneighbour/debuglogger';
const customLogger = new debuglogger(true, 'warn');
customLogger.log('This will not log because log level is warn');
customLogger.warn('This is a warning');
customLogger.error('This is an error');Setting an External Log Handler
logger.setHandler((method, args) => {
if (method === 'error') {
// Send error logs to a server
sendToServer(args);
}
});
logger.error('An error occurred'); // This will trigger the custom handlerChanging Log Levels Dynamically
logger.setLogLevel('info');
logger.debug('This will not log');
logger.info('This will log');Replacing Console Methods Globally
import { replaceConsole, restoreConsole } from './debuglogger.js';
replaceConsole(logger);
console.log('This is now handled by debuglogger');
restoreConsole(); // Restore original console methodsLicense
This project is licensed under the MIT License.