Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate to consume webpack built-in logger #361

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/Logger.js
Expand Up @@ -6,14 +6,28 @@ const LEVELS = [
'silent'
];

const loggerMethods = [
'log',
'trace',
'group',
'groupEnd',
'groupEndCollapsed',
'status',
'clear',
'profile'
];

const LEVEL_TO_CONSOLE_METHOD = new Map([
['debug', 'log'],
['info', 'log'],
['warn', 'log']
]);

class Logger {
const webpackLogger = require('webpack/lib/logging/runtime')

if (webpackLogger.getLogger) LEVELS.push(...loggerMethods);

class Logger {
static levels = LEVELS;
static defaultLevel = 'info';

Expand All @@ -35,7 +49,11 @@ class Logger {
}

_log(level, ...args) {
console[LEVEL_TO_CONSOLE_METHOD.get(level) || level](...args);
if (webpackLogger.getLogger) {
webpackLogger.getLogger('webpack-bundle-analyzer')[level](...args)
} else {
console[LEVEL_TO_CONSOLE_METHOD.get(level) || level](...args);
}
}

};
Expand All @@ -48,4 +66,4 @@ LEVELS.forEach(level => {
};
});

module.exports = Logger;
module.exports = Logger