{"id":14981895,"url":"https://github.com/coreprocess/babel-plugin-js-logger","last_synced_at":"2025-10-08T11:33:39.278Z","repository":{"id":143845925,"uuid":"79588902","full_name":"coreprocess/babel-plugin-js-logger","owner":"coreprocess","description":"Babel plugin to enable js-logger in your entire project efficiently.","archived":false,"fork":false,"pushed_at":"2020-10-31T20:04:42.000Z","size":15,"stargazers_count":13,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-30T08:20:37.846Z","etag":null,"topics":["babeljs","browser","configurable","javascript","log-all","logger","named-logger","nodejs","plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coreprocess.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["coreprocess"]}},"created_at":"2017-01-20T19:05:50.000Z","updated_at":"2023-04-19T16:01:30.000Z","dependencies_parsed_at":"2023-07-25T21:15:56.477Z","dependency_job_id":null,"html_url":"https://github.com/coreprocess/babel-plugin-js-logger","commit_stats":null,"previous_names":["core-process/babel-plugin-js-logger"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreprocess%2Fbabel-plugin-js-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreprocess%2Fbabel-plugin-js-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreprocess%2Fbabel-plugin-js-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreprocess%2Fbabel-plugin-js-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coreprocess","download_url":"https://codeload.github.com/coreprocess/babel-plugin-js-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245895311,"owners_count":20690045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["babeljs","browser","configurable","javascript","log-all","logger","named-logger","nodejs","plugin"],"created_at":"2024-09-24T14:04:27.172Z","updated_at":"2025-10-08T11:33:34.233Z","avatar_url":"https://github.com/coreprocess.png","language":"JavaScript","readme":"# babel-plugin-js-logger\n\nBabel plugin to enable js-logger in your entire project efficiently.\n\n![npm downloads total](https://img.shields.io/npm/dt/babel-plugin-js-logger.svg) ![npm version](https://img.shields.io/npm/v/babel-plugin-js-logger.svg) ![npm license](https://img.shields.io/npm/l/babel-plugin-js-logger.svg)\n\nThis [Babel](https://babeljs.io/) plugin enables [js-logger](https://github.com/jonnyreeves/js-logger) in your entire project by placing `const logger = require('js-logger').get('project:example:path');` in front of every transpiled JavaScript file. Works with Babel standalone, e.g. within a backend, or together with Webpack, e.g. within a frontend.\n\nHave a look at our [logger-example](https://github.com/coreprocess/logger-example) project. It is a self-contained showcase on how to use js-logger within your backend and frontend code efficiently.\n\n## Installation\n\nInstall `js-logger` and the plugin module via\n\n```sh\nnpm install js-logger --save\nnpm install babel-plugin-js-logger --save-dev\n```\n\nor\n\n```sh\nyarn add js-logger\nyarn add babel-plugin-js-logger --dev\n```\n\n## Configuration\n\n### Enable Plugin\n\nAdd `babel-plugin-js-logger` to your `.babelrc`, e.g. like this:\n\n```json\n{\n  \"presets\": [\"es2015\", \"stage-0\", \"react\"],\n  \"plugins\": [\"transform-runtime\", \"transform-decorators-legacy\", \"js-logger\"]\n}\n```\n#### Initialize Logger\n\nInitialize `js-logger` in your main routine with `require('js-logger').useDefaults();`. See [js-logger/readme](https://github.com/jonnyreeves/js-logger/blob/master/README.md) for more.\n\n##### Be aware:\n\nIn case you use `import` instead of `require` to import your modules, you will have to outsource the initialization routine into a separate file which has to be imported at the very first. **Reason**: import statements are moved to the top of every file automatically since this is required by the standard and Babel complies to it. Otherwise, you will run your code to initialize `js-logger` a bit later in the process than you truly intend to do and you might miss a few logging messages.\n\nI use this pattern in my projects:\n\n1) `main.js`: Import your `logger-init.js` at the very first in your main entry point.\n\n```js\nimport './logger-init.js';\nimport ExampleModule from './example-module.js';\n...\n```\n\n2) `logger-init.js`: Run your initialization code for `js-logger` here.\n\n```js\nrequire('js-logger').useDefaults();\n```\n\n### Options\n\nThe plugin provides the following options to tweak the behavior of the plugin during code generation.\n\n| Option | Values | Default | Description  |\n| :--- | :--- | :--- | :--- |\n| `variable` | Valid JS identifier | `\"logger\"` | Name of the logger variable |\n| `module` | Valid NodeJS module name | `\"js-logger\"` | Name of the logger module |\n| `factory` | Valid JS identifier | `\"get\"` | Name of the logger factory method (called on the module) |\n| `format` | `{ project: Boolean, level: Integer, separator: String, extensions: Array\u003cString\u003e }` | `{ project: true, level: -1, separator: ':', extensions: [ '.js', '.jsx' ] }` | Parametrizes the logger name to be generated (see below) |\n\n#### Logger name formatting\n\nThe `format` options parametrize the logger name to be generated.\n\n| Option | Values | Description  |\n| :--- | :--- | :--- |\n| `project` | `true` | Include the project name provided in the `package.json` |\n| `project` | `false` | Do not include the project name |\n| `level` | `0` | Use the full path starting from the project root (= directory where `package.json` was found) |\n| `level` | `\u003c 0` | Use the full path starting from the `n`th level below the project root (very useful to omit the name of the `src` directory used in projects) |\n| `level` | `\u003e 0` | Use the last `n` levels of the path  |\n| `separator` | e.g. `:` | Use `:` as a namespace separator |\n| `extensions` | e.g. `[ '.js', '.jsx' ]` | Strip `.js` and `.jsx` extensions from path |\n\n#### Configuration Example\n\nA `.babelrc` configuration example which uses dots as separators and omits the project name.\n\n```js\n{\n  \"presets\": [ \"es2015\", \"stage-0\", \"react\" ],\n  \"plugins\": [ \"transform-runtime\", \"transform-decorators-legacy\",\n    [ \"js-logger\", { \"format\": { \"separator\": \".\", \"project\": false } } ]\n  ]\n}\n```\n\n## Usage\n\nOnce you configured the plugin, you can use the logger in every JS file easily via the `logger` variable. See [js-logger/readme](https://github.com/jonnyreeves/js-logger/blob/master/README.md) for more.\n\n### Example\n\nThe file `my-project/src/some/sub/module.js`\n\n```js\nlogger.debug(\"some debug message\");\n```\n\nwould produce the output\n\n```\n[my-project:some:sub:module] some debug message\n```\nif used with default configuration and a `my-project/package.json` providing the project name `my-project`.\n","funding_links":["https://github.com/sponsors/coreprocess"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoreprocess%2Fbabel-plugin-js-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoreprocess%2Fbabel-plugin-js-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoreprocess%2Fbabel-plugin-js-logger/lists"}