JSPM

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

Enhanced console logging with remote capabilities

Package Exports

  • consoleiq
  • consoleiq/index.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 (consoleiq) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ConsoleIQ

npm version license downloads

Enhanced console logging with remote capabilities for any JavaScript environment

ConsoleIQ provides powerful console logging enhancements with built-in remote reporting, error handling, and framework integrations - all in a lightweight package.

Features

  • 🌐 Universal - Works in browsers, Node.js, and any JavaScript runtime with consistent API
  • â˜ī¸ Remote Ready - Built-in support for sending logs to any HTTP endpoint with configurable levels
  • đŸ›Ąī¸ Error Handling - Automatic error capturing with stack traces and environment context
  • 🎨 Colorized Output - Enhanced terminal/console output with customizable colorization
  • 🔄 Framework Support - Integration examples for React, Vue, Angular, and Node.js/Express
  • đŸĒļ Lightweight - Zero dependencies (except axios for HTTP requests)

Installation

npm install consoleiq

Basic Usage

const ConsoleIQ = require('consoleiq');

// Initialize with default options
const logger = new ConsoleIQ().init();

// Use enhanced console methods
console.log('Regular log message');
console.info('Info message');
console.warn('Warning message');
console.error('Error message');
console.debug('Debug message');

// Custom text method for remote logging
console.text('This will be sent to remote endpoint if configured');

Configuration

const logger = new ConsoleIQ({
  endpoint: 'https://api.your-log-service.com/logs',
  apiKey: 'your-api-key-here',
  colorize: true,
  silent: false,
  name: 'MyAppLogger',
  allowedLevels: ['error', 'warn', 'text'],
  captureGlobalErrors: true,
  captureUnhandledRejections: true,
  autoTraceErrors: true,
  enhanceErrors: true,
  maxErrorDepth: 5,
  environment: 'browser' // or 'node'
}).init();

Configuration Options

Option Type Default Description
endpoint string "" URL endpoint for remote logging
apiKey string null API key for authentication
colorize boolean true Enable/disable colored output
silent boolean false Suppress all console output
name string "ConsoleIQ" Logger instance name
allowedLevels Array ["error", "text"] Levels to send remotely
captureGlobalErrors boolean true Capture uncaught exceptions
captureUnhandledRejections boolean true Capture promise rejections
captureConsoleErrors boolean true Capture console.error calls
autoTraceErrors boolean true Add stack traces to errors
enhanceErrors boolean true Add context to error objects
maxErrorDepth number 5 Max depth for error serialization
environment string auto-detected Force environment (browser/node)

Advanced Features

Environment Detection

ConsoleIQ automatically detects whether it's running in a browser or Node.js environment and adjusts its behavior accordingly.

// In browser:
logger.getConfig().environment === 'browser'

// In Node.js:
logger.getConfig().environment === 'node'

Error Handling

Comprehensive error handling with stack traces, environment context, and automatic serialization of complex error objects.

// Enhanced error object includes:
{
  message: 'Error message',
  stack: 'Cleaned stack trace',
  timestamp: 'ISO string',
  environment: 'browser',
  browser: { url, userAgent, platform },
  // ...and any custom error properties
}

Remote Logging

Send logs to any HTTP endpoint with configurable levels and automatic retries. The payload includes rich metadata:

{
  "level": "error",
  "message": "Form validation failed",
  "timestamp": "2025-04-30T12:34:56.789Z",
  "name": "MyAppLogger",
  "environment": "browser",
  "metadata": {
    "browser": {
      "url": "https://example.com/form",
      "userAgent": "Mozilla/5.0...",
      "platform": "Win32"
    }
  },
  "stack": "Error: Validation failed... (clean stack trace)"
}

Framework Integration

React Hook

import { useEffect } from 'react';
import ConsoleIQ from 'consoleiq';

export function useConsoleIQ(config) {
  useEffect(() => {
    const logger = new ConsoleIQ(config).init();
    return () => logger.restore();
  }, [config?.endpoint]); // Re-init if endpoint changes
}

Vue Plugin

import ConsoleIQ from 'consoleiq';

export default {
  install(app, config) {
    const logger = new ConsoleIQ(config).init();
    app.provide('logger', logger);
    app.config.globalProperties.$logger = logger;
  }
};

Angular Service

import { Injectable, OnDestroy } from '@angular/core';
import ConsoleIQ from 'consoleiq';

@Injectable({ providedIn: 'root' })
export class LoggerService implements OnDestroy {
  private logger: ConsoleIQ;

  constructor() {
    this.logger = new ConsoleIQ({
      name: 'AngularApp'
    }).init();
  }

  ngOnDestroy() {
    this.logger.restore();
  }
}

Node.js/Express

const ConsoleIQ = require('consoleiq');

// For server-side usage
const logger = new ConsoleIQ({
  endpoint: process.env.LOGGING_ENDPOINT,
  captureGlobalErrors: true,
  environment: 'node'
}).init();

// Use in Express middleware
app.use((req, res, next) => {
  console.text(`Request: ${req.method} ${req.path}`);
  next();
});

Key Benefits

  • Enhanced console methods with colorization and remote logging
  • Automatic capture of uncaught exceptions and promise rejections
  • Error object enhancement with environment context
  • Configurable log levels and filtering
  • Circular reference handling in object serialization
  • Framework-specific integration examples
  • Lightweight with zero dependencies (except axios for HTTP)

License

MIT Š 2025 ConsoleIQ