JSPM

@davidsneighbour/debuglogger

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q54034F
  • License MIT

A customizable logging wrapper for debugging with log levels, external handlers, and console replacement.

Package Exports

  • @davidsneighbour/debuglogger
  • @davidsneighbour/debuglogger/dist/debuglogger.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@davidsneighbour/debuglogger) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.