All Projects → coreprocess → babel-plugin-js-logger

coreprocess / babel-plugin-js-logger

Licence: other
Babel plugin to enable js-logger in your entire project efficiently.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to babel-plugin-js-logger

logback-access-spring-boot-starter
Spring Boot Starter for Logback-access.
Stars: ✭ 153 (+1175%)
Mutual labels:  logger
G-Earth
Cross-platform Habbo packet manipulator
Stars: ✭ 52 (+333.33%)
Mutual labels:  logger
base
OST Base provides advanced Promise Queue Manager and other utilities.
Stars: ✭ 19 (+58.33%)
Mutual labels:  logger
JJSwiftLog
Swift log library for all platform
Stars: ✭ 51 (+325%)
Mutual labels:  logger
wlog
A simple logging interface that supports cross-platform color and concurrency.
Stars: ✭ 59 (+391.67%)
Mutual labels:  logger
phoenix passwordless login
Phoenix Passwordless Login
Stars: ✭ 28 (+133.33%)
Mutual labels:  logger
LogDNA-Android-Client
Android client for LogDNA
Stars: ✭ 22 (+83.33%)
Mutual labels:  logger
winston-dev-console
Winston@3 console format aimed to improve development UX
Stars: ✭ 88 (+633.33%)
Mutual labels:  logger
spdlog-python
python wrapper around C++ spdlog ([email protected]:gabime/spdlog.git)
Stars: ✭ 46 (+283.33%)
Mutual labels:  logger
Android-NativeLogger
Android Logger
Stars: ✭ 21 (+75%)
Mutual labels:  logger
DRF-API-Logger
An API Logger for your Django Rest Framework project.
Stars: ✭ 184 (+1433.33%)
Mutual labels:  logger
workflow-svg.js
JS Library to present and edit workflows as SVG
Stars: ✭ 30 (+150%)
Mutual labels:  configurable
QLogger
Multi-threading logger for Qt applications
Stars: ✭ 46 (+283.33%)
Mutual labels:  logger
lines-logger
Browser logger that rests lines in peace
Stars: ✭ 26 (+116.67%)
Mutual labels:  logger
EventLogger
Log event count and event time in iOS
Stars: ✭ 21 (+75%)
Mutual labels:  logger
perforce-commit-discord-bot
🗒️ ✏️Posts the most recent commit messages from a Perforce version control server to a Discord channel.
Stars: ✭ 22 (+83.33%)
Mutual labels:  logger
ng2-logger
Isomorphic logger for Browser and NodeJS, ( typescript / javascript ) apps
Stars: ✭ 61 (+408.33%)
Mutual labels:  logger
hapi-good-winston
A good reporter to send and log events with winston
Stars: ✭ 21 (+75%)
Mutual labels:  logger
telegram-logger-errors
Telegram logger errors package laravel | Laravel пакет telegram логгер ошибок
Stars: ✭ 15 (+25%)
Mutual labels:  logger
RxLogs
An Android & Kotlin Reactive Advanced Logging Framework.
Stars: ✭ 12 (+0%)
Mutual labels:  logger

babel-plugin-js-logger

Babel plugin to enable js-logger in your entire project efficiently.

npm downloads total npm version npm license

This Babel plugin enables 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.

Have a look at our logger-example project. It is a self-contained showcase on how to use js-logger within your backend and frontend code efficiently.

Installation

Install js-logger and the plugin module via

npm install js-logger --save
npm install babel-plugin-js-logger --save-dev

or

yarn add js-logger
yarn add babel-plugin-js-logger --dev

Configuration

Enable Plugin

Add babel-plugin-js-logger to your .babelrc, e.g. like this:

{
  "presets": ["es2015", "stage-0", "react"],
  "plugins": ["transform-runtime", "transform-decorators-legacy", "js-logger"]
}

Initialize Logger

Initialize js-logger in your main routine with require('js-logger').useDefaults();. See js-logger/readme for more.

Be aware:

In 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.

I use this pattern in my projects:

  1. main.js: Import your logger-init.js at the very first in your main entry point.
import './logger-init.js';
import ExampleModule from './example-module.js';
...
  1. logger-init.js: Run your initialization code for js-logger here.
require('js-logger').useDefaults();

Options

The plugin provides the following options to tweak the behavior of the plugin during code generation.

Option Values Default Description
variable Valid JS identifier "logger" Name of the logger variable
module Valid NodeJS module name "js-logger" Name of the logger module
factory Valid JS identifier "get" Name of the logger factory method (called on the module)
format { project: Boolean, level: Integer, separator: String, extensions: Array<String> } { project: true, level: -1, separator: ':', extensions: [ '.js', '.jsx' ] } Parametrizes the logger name to be generated (see below)

Logger name formatting

The format options parametrize the logger name to be generated.

Option Values Description
project true Include the project name provided in the package.json
project false Do not include the project name
level 0 Use the full path starting from the project root (= directory where package.json was found)
level < 0 Use the full path starting from the nth level below the project root (very useful to omit the name of the src directory used in projects)
level > 0 Use the last n levels of the path
separator e.g. : Use : as a namespace separator
extensions e.g. [ '.js', '.jsx' ] Strip .js and .jsx extensions from path

Configuration Example

A .babelrc configuration example which uses dots as separators and omits the project name.

{
  "presets": [ "es2015", "stage-0", "react" ],
  "plugins": [ "transform-runtime", "transform-decorators-legacy",
    [ "js-logger", { "format": { "separator": ".", "project": false } } ]
  ]
}

Usage

Once you configured the plugin, you can use the logger in every JS file easily via the logger variable. See js-logger/readme for more.

Example

The file my-project/src/some/sub/module.js

logger.debug("some debug message");

would produce the output

[my-project:some:sub:module] some debug message

if used with default configuration and a my-project/package.json providing the project name my-project.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].