{"id":19090,"library":"babel-plugin-js-logger","title":"babel-plugin-js-logger","description":"Babel plugin that automatically inserts a logger declaration (via js-logger) at the top of every transpiled JavaScript file, enabling consistent logging across backend and frontend projects. Current stable version: 1.0.17. Maintained as of early 2021, with infrequent updates. Key differentiators: automatic logger instantiation per file, configurable logger name formatting (project/level/separator/extensions), and support for both Babel standalone and Webpack. Alternative to manual logger setup in each file. Note: requires js-logger as a peer dependency and Babel as a build tool.","status":"active","version":"1.0.17","language":"javascript","source_language":"en","source_url":"https://github.com/core-process/babel-plugin-js-logger","tags":["javascript"],"install":[{"cmd":"npm install babel-plugin-js-logger","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-js-logger","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-js-logger","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The plugin generates code that requires js-logger at runtime","package":"js-logger","optional":false}],"imports":[{"note":"The plugin is a Babel plugin, not a runtime import. It is configured in .babelrc or babel.config.js.","symbol":"plugin","correct":"// Add 'js-logger' to .babelrc plugins array: { \"plugins\": [\"js-logger\"] }"},{"note":"js-logger is a runtime dependency that must be installed separately.","symbol":"js-logger","correct":"import 'js-logger'; // or const Logger = require('js-logger');"},{"note":"The plugin automatically generates these calls per file. The factory option defaults to 'get'.","wrong":"const logger = Logger.get('my:name'); // correct usage","symbol":"get","correct":"const logger = Logger.get('my:name');"}],"quickstart":{"code":"// Install: npm install js-logger --save && npm install babel-plugin-js-logger --save-dev\n\n// .babelrc\n{\n  \"plugins\": [\"js-logger\"]\n}\n\n// In your main entry point (e.g., main.js)\nrequire('js-logger').useDefaults(); // initialize js-logger\n\n// All other files will automatically have a logger variable\n// Example: some/path/file.js\n// The plugin inserts: const logger = require('js-logger').get('project:some:path:file');\n\n// Use logger\nlogger.info('Hello from file!');","lang":"javascript","description":"Installs and configures the plugin, initializes js-logger, and demonstrates automatic logger insertion per file."},"warnings":[{"fix":"Use a separate init file imported first, e.g., import './logger-init.js'; (see README).","message":"With ES modules (import), the plugin's generated logger declaration may execute after imports due to hoisting, causing initialization order issues.","severity":"gotcha","affected_versions":"*"},{"fix":"Consider using manual logger setup if tree-shaking is critical.","message":"The plugin automatically inserts a require() for js-logger even if it's not used, potentially causing tree-shaking to fail.","severity":"gotcha","affected_versions":"*"},{"fix":"Test with your project structure and adjust level or extensions accordingly.","message":"The format option 'level' with negative values counts from the project root, which may include unwanted directories if project root detection fails.","severity":"gotcha","affected_versions":"*"},{"fix":"Use @babel/preset-typescript and ensure the plugin runs after it.","message":"The plugin does not support TypeScript natively; TypeScript files must be handled by Babel with appropriate presets.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install js-logger as a dependency: npm install js-logger --save","cause":"js-logger is not installed or not in node_modules.","error":"Module not found: Error: Can't resolve 'js-logger'"},{"fix":"Install the plugin: npm install babel-plugin-js-logger --save-dev, then add 'js-logger' to .babelrc plugins array.","cause":"The plugin is not installed or not listed in .babelrc plugins correctly.","error":"Error: Cannot find module 'babel-plugin-js-logger'"},{"fix":"Call require('js-logger').useDefaults() before using the generated logger variables.","cause":"js-logger is not initialized properly.","error":"TypeError: require(...).useDefaults is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}