probe.gl Instrumentation and Logging

3.6.0 · active · verified Sun Apr 19

probe.gl is a robust collection of JavaScript tools designed for console-focused logging, performance instrumentation, benchmarking, and testing across both browser and Node.js environments. The current stable version is 3.6.0. It is developed and maintained as part of the vis.gl open-source visualization suite by Uber, indicating a steady release cadence tied to the evolution of their larger ecosystem. Key differentiators include its 'off by default' design to ensure a minimal performance footprint when not actively used, its lightweight nature, and features like persistent configuration through local storage. It enhances the debugging experience with capabilities such as defeating log cascades (to prevent console flooding) and providing direct source code links from console messages. The library offers a more advanced approach to application insights compared to basic `console.log`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates enabling probe.gl, setting log levels, using logging utilities, and basic performance timing with a `Timer`.

import Probe from 'probe.gl';
import { log } from '@probe.gl/log';
import { Timer } from '@probe.gl/stats';

// 1. Enable Probe and set logging level
// Probe is 'off by default' to minimize performance impact.
Probe.enable().setLevel(3); // Enable all features and verbose logging
Probe.configure({ isPrintEnabled: true }); // Ensure messages are printed to console

console.log('Probe.gl initialized. Check browser console for detailed logs.');

// 2. Use basic logging utilities
log.log('Application started successfully.');
log.warn('A non-critical issue detected.', { code: 101, details: 'Example warning payload' });
log.error('Failed to load critical resource!', new Error('Resource not found'));

// 3. Measure performance with a Timer
const myTimer = new Timer('ExpensiveOperation');

function performExpensiveOperation() {
  myTimer.start();
  // Simulate some work
  let sum = 0;
  for (let i = 0; i < 1000000; i++) {
    sum += Math.sqrt(i);
  }
  myTimer.end(); // Automatically logs duration if Probe is enabled
  log.log(`Result of expensive operation: ${sum}`);
}

performExpensiveOperation();

// 4. Using the main Probe object for options
if (Probe.getOption('myFeatureFlag')) {
  log.log('Custom feature flag \'myFeatureFlag\' is enabled.');
} else {
  log.log('Custom feature flag \'myFeatureFlag\' is disabled, configuring it...');
  Probe.configure({ myFeatureFlag: true });
  log.log('Custom feature flag \'myFeatureFlag\' is now enabled for subsequent checks.');
}

view raw JSON →