Lighthouse Logger

2.0.2 · maintenance · verified Sun Apr 19

The `lighthouse-logger` package provides a shared logging utility class primarily used internally by the Google Lighthouse project and its associated tools. It offers basic logging capabilities with a focus on integrating within the Lighthouse ecosystem. The current stable version is 2.0.2, last published 8 months ago, and it ships with TypeScript types for improved developer experience. While the broader Lighthouse project updates frequently with Chrome DevTools releases, `lighthouse-logger` maintains a more independent and slower release cycle. Its key differentiators include its tight integration with Lighthouse's internal architecture and its minimal set of dependencies, notably `debug` and `marky`. However, discussions within the Lighthouse team suggest that maintaining `lighthouse-logger` as an external npm package is considered "awkward," and there's consideration for deprecating its external use, potentially leading to a maintenance-only status or advising direct internal referencing for Lighthouse itself.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import the Logger class, set its logging level, and use various logging methods.

import { Logger, setLevel } from 'lighthouse-logger';

// Set the desired logging level (e.g., 'verbose', 'log', 'info', 'warn', 'error', 'silent')
// By default, it might log based on debug environment variables or a default level.
setLevel('verbose');

const myLogger = new Logger('my-app');

myLogger.log('Starting application...');
myLogger.info('Configuration loaded successfully.');
myLogger.warn('Potential issue: API endpoint might be deprecated.');
myLogger.error('Critical error: Failed to connect to database!');

// Example of more detailed logging with specific log IDs
myLogger.log('Processing data for user', { userId: 123, dataSize: '1.5MB' });

// You can also create sub-loggers for different modules
const dataProcessorLogger = new Logger('my-app:data-processor');
dataProcessorLogger.verbose('Entering data processing module.');

// Example of setting level via environment variable for Node.js
// process.env.DEBUG = 'my-app*' // This would enable debug logs for 'my-app' namespace
console.log('\nCheck your console output for logs. Note: ' + 
            'Actual output depends on environment variables (e.g., DEBUG) and setLevel call.');

view raw JSON →