0.2.0 • Published 10 months ago

@davidsneighbour/debuglogger v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

debuglogger is a customizable logging wrapper that enhances debugging with log levels, external handlers, and console replacement.

Installation

npm install @davidsneighbour/debuglogger

Usage

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 handler

Changing 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 methods

License

This project is licensed under the MIT License.

0.2.0

10 months ago

0.1.1

10 months ago

0.1.0

1 year ago

0.0.4

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago