webpack/lib/logging/runtime.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-07-24 16:51:04 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
2023-06-17 01:13:03 +08:00
const { SyncBailHook } = require("tapable");
2019-07-19 18:31:18 +08:00
const { Logger } = require("./Logger");
const createConsoleLogger = require("./createConsoleLogger");
2019-07-19 18:31:18 +08:00
/** @type {createConsoleLogger.LoggerOptions} */
2024-07-31 04:09:42 +08:00
const currentDefaultLoggerOptions = {
2019-07-22 04:28:46 +08:00
level: "info",
debug: false,
console
2019-07-22 04:28:46 +08:00
};
let currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
2019-07-22 04:28:46 +08:00
/**
* @param {string} name name of the logger
* @returns {Logger} a logger
*/
2019-07-19 18:31:18 +08:00
exports.getLogger = name => {
return new Logger(
(type, args) => {
if (exports.hooks.log.call(name, type, args) === undefined) {
currentDefaultLogger(name, type, args);
}
},
childName => exports.getLogger(`${name}/${childName}`)
);
2019-07-19 18:31:18 +08:00
};
2019-07-22 04:28:46 +08:00
/**
* @param {createConsoleLogger.LoggerOptions} options new options, merge with old options
2019-07-22 04:28:46 +08:00
* @returns {void}
*/
exports.configureDefaultLogger = options => {
Object.assign(currentDefaultLoggerOptions, options);
currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
2019-07-22 04:28:46 +08:00
};
2019-07-19 18:31:18 +08:00
exports.hooks = {
log: new SyncBailHook(["origin", "type", "args"])
};