Embed meaningful logs into your webpack bundle.
- Node 7.5.0 or newer (not tested on earlier versions)
- Typescript 2.1.5 or newer (not tested on earlier versions)
- Babel 6.2.2 or newer (not tested on earlier versions)
npm i logs-loader --save-dev
or
yarn add logs-loader --dev
A webpack loader that enhances your logs by adding the file and the object logging.
Note: put it before any linter in your webpack config "module->rules->use" list to prevent max-line-length warnings.
const test = ['test'];
console.info(test.length);
const path = require("path");
module.exports = {
entry: {
app: path.resolve(__dirname, "src", "index.js")
},
output: {
path: path.resolve(__dirname, "build"),
filename: "app.js"
},
module: {
rules: [
{
test: /\.tsx?$/,
include: [
path.resolve(__dirname, 'src'),
],
use: [
{
loader: 'babel-loader',
query: {
babelrc: false,
extends: path.resolve(__dirname, '.babelrc'),
plugins: [
...(
!production ? [
"react-hot-loader/babel",
] : []
),
...(
production ? [
"transform-remove-console",
// ["transform-replace-object-assign", "simple.assign"],
] : []
),
],
},
},
{loader: 'ts-loader', options: {transpileOnly: false}},
{
loader: 'logs-loader',
query: {
patterns: ["console"],
},
},
{loader: 'tslint-loader'},
],
},
{
test: /\.jsx?$/,
include: [
path.resolve(__dirname, 'src'),
],
use: [
{loader: 'babel-loader'},
{
loader: 'logs-loader',
query: {
patterns: ["console"],
},
},
],
},
],
},
};
const test = ['test'];
console.log("/src/index.js:2:test.length", test.length);
By default it modifies all console commands: console.error, console.log... But it can be customized. To modify all winstons logs the "patterns" would be:
query: {
patterns: ["winston"],
},
const test = ['test'];
winston(test.length);
winston.info(test.length);
const test = ['test'];
winston("/src/index.js:2:test.length", test.length);
winston.info("/src/index.js:3:test.length", test.length);
Or
query: {
patterns: ["winston"],
customLevels: ["debug1", "debug2"],
},
const test = ['test'];
winston.debug1(test.length);
winston.debug2(test.length);
const test = ['test'];
winston.debug1("/src/index.js:2:test.length", test.length);
winston.debug2("/src/index.js:3:test.length", test.length);
Props | Options | Default | Description |
---|---|---|---|
patterns | string or Array[string] | ["console"] | Sets pattern of logger call. |
customLevels | string or Array[string] | [] | Sets additional custom logging levels. |
- Submit an issue
- Fork the repository
- Create a dedicated branch (never ever work in
master
) - The first time, run command:
yarn
into the directory - Fix bugs or implement features
- Add tests
- Add examples directory
This project is licensed under the terms of the MIT license