{"id":14672,"library":"lighthouse-logger","title":"Lighthouse Logger","description":"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.","status":"maintenance","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/GoogleChrome/lighthouse","tags":["javascript","typescript"],"install":[{"cmd":"npm install lighthouse-logger","lang":"bash","label":"npm"},{"cmd":"yarn add lighthouse-logger","lang":"bash","label":"yarn"},{"cmd":"pnpm add lighthouse-logger","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for conditional debug logging.","package":"debug","optional":false},{"reason":"Used for performance marking and measurements within the logger.","package":"marky","optional":false}],"imports":[{"note":"The primary export is a Logger class. Version 2.x is designed for ES Modules.","wrong":"const Logger = require('lighthouse-logger');","symbol":"Logger","correct":"import { Logger } from 'lighthouse-logger';"},{"note":"A utility function to control the logging verbosity programmatically. ESM-only.","wrong":"const { setLevel } = require('lighthouse-logger');","symbol":"setLevel","correct":"import { setLevel } from 'lighthouse-logger';"},{"note":"There is no default export; all utilities are named exports. CommonJS requires the `require()` syntax.","wrong":"import LighthouseLogger from 'lighthouse-logger';","symbol":"*","correct":"import * as LighthouseLogger from 'lighthouse-logger';"}],"quickstart":{"code":"import { Logger, setLevel } from 'lighthouse-logger';\n\n// Set the desired logging level (e.g., 'verbose', 'log', 'info', 'warn', 'error', 'silent')\n// By default, it might log based on debug environment variables or a default level.\nsetLevel('verbose');\n\nconst myLogger = new Logger('my-app');\n\nmyLogger.log('Starting application...');\nmyLogger.info('Configuration loaded successfully.');\nmyLogger.warn('Potential issue: API endpoint might be deprecated.');\nmyLogger.error('Critical error: Failed to connect to database!');\n\n// Example of more detailed logging with specific log IDs\nmyLogger.log('Processing data for user', { userId: 123, dataSize: '1.5MB' });\n\n// You can also create sub-loggers for different modules\nconst dataProcessorLogger = new Logger('my-app:data-processor');\ndataProcessorLogger.verbose('Entering data processing module.');\n\n// Example of setting level via environment variable for Node.js\n// process.env.DEBUG = 'my-app*' // This would enable debug logs for 'my-app' namespace\nconsole.log('\\nCheck your console output for logs. Note: ' + \n            'Actual output depends on environment variables (e.g., DEBUG) and setLevel call.');","lang":"typescript","description":"Demonstrates how to import the Logger class, set its logging level, and use various logging methods."},"warnings":[{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=2.0.0"},{"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).","message":"Version 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.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"Attempting to import `lighthouse-logger` (an ES Module) using CommonJS `require()` in a context where only ESM is expected or configured.","error":"ERR_REQUIRE_ESM: require() of ES Module .../node_modules/lighthouse-logger/index.js from .../my-app.js not supported"},{"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.","cause":"The `Logger` class might not be correctly imported or accessed, often due to incorrect import syntax for named exports.","error":"TypeError: Logger is not a constructor"}],"ecosystem":"npm"}