CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-loglevel

Minimal lightweight logging for JavaScript, adding reliable log level methods to any available console.log methods

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

basic-logging.mddocs/

Basic Logging

loglevel provides five core logging methods that offer reliable output across all JavaScript environments with proper fallbacks and preserved line numbers.

Capabilities

trace

/**
 * Output trace message with full stack trace
 * This will include a full stack trace in supported environments
 * @param {...any} msg - Any data to log to the console
 */
trace(...msg: any[]): void;

Usage Examples:

import log from 'loglevel';

log.setLevel('trace');
log.trace('Entering function processData()');
log.trace('Processing item:', { id: 123, name: 'example' });
log.trace('Variable state:', { count: 42, active: true });

debug

/**
 * Output debug message to console
 * Maps to console.debug() if available, otherwise console.log()
 * @param {...any} msg - Any data to log to the console
 */
debug(...msg: any[]): void;

Usage Examples:

import log from 'loglevel';

log.setLevel('debug');
log.debug('Cache miss for key:', 'user_123');
log.debug('API response:', { status: 200, data: [...] });
log.debug('Performance metric:', { duration: 245, memory: '12MB' });

log

/**
 * Alias for the debug method
 * Provides familiar console.log-style interface
 * @param {...any} msg - Any data to log to the console
 */
log(...msg: any[]): void;

Usage Examples:

import logger from 'loglevel';

logger.setLevel('debug');
logger.log('This is equivalent to debug()');
logger.log('User action:', 'clicked_button', { buttonId: 'submit' });

info

/**
 * Output informational message
 * Maps to console.info() if available, otherwise console.log()
 * @param {...any} msg - Any data to log to the console
 */
info(...msg: any[]): void;

Usage Examples:

import log from 'loglevel';

log.setLevel('info');
log.info('Application started successfully');
log.info('User logged in:', { userId: 456, username: 'john_doe' });
log.info('Configuration loaded:', { theme: 'dark', locale: 'en-US' });

warn

/**
 * Output warning message
 * Maps to console.warn() if available, otherwise console.log()
 * @param {...any} msg - Any data to log to the console
 */
warn(...msg: any[]): void;

Usage Examples:

import log from 'loglevel';

log.setLevel('warn');
log.warn('Deprecated API usage detected');
log.warn('Low disk space:', { available: '100MB', threshold: '500MB' });
log.warn('Rate limit approaching:', { requests: 95, limit: 100 });

error

/**
 * Output error message
 * Maps to console.error() if available, otherwise console.log()
 * @param {...any} msg - Any data to log to the console
 */
error(...msg: any[]): void;

Usage Examples:

import log from 'loglevel';

log.setLevel('error');
log.error('Database connection failed');
log.error('Validation error:', { field: 'email', message: 'Invalid format' });
log.error('Unhandled exception:', error.stack);

Environment Behavior

loglevel automatically adapts to different environments:

  • Modern Browsers: Uses appropriate console methods (console.trace, console.debug, etc.)
  • Old Browsers: Falls back to console.log or no-op if console unavailable
  • Node.js: Works with Node's console implementation
  • IE8/9: Handles delayed console availability when dev tools are opened
// Graceful handling - never throws errors
log.info('This works everywhere');

// Preserves line numbers and stack traces
log.debug('Check browser dev tools for accurate source location');

docs

basic-logging.md

index.md

level-control.md

multi-logger.md

plugins.md

tile.json