webpack/lib/logging/runtime.js

46 lines
1.2 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
2025-07-03 17:06:45 +08:00
/**
* @param {createConsoleLogger.LoggerOptions} options new options, merge with old options
* @returns {void}
*/
module.exports.configureDefaultLogger = (options) => {
2025-07-03 17:06:45 +08:00
Object.assign(currentDefaultLoggerOptions, options);
currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
};
2019-07-22 04:28:46 +08:00
/**
* @param {string} name name of the logger
* @returns {Logger} a logger
*/
module.exports.getLogger = (name) =>
2024-07-31 11:31:11 +08:00
new Logger(
(type, args) => {
2024-07-31 04:54:55 +08:00
if (module.exports.hooks.log.call(name, type, args) === undefined) {
currentDefaultLogger(name, type, args);
}
},
(childName) => module.exports.getLogger(`${name}/${childName}`)
);
2019-07-19 18:31:18 +08:00
2024-07-31 04:54:55 +08:00
module.exports.hooks = {
2019-07-19 18:31:18 +08:00
log: new SyncBailHook(["origin", "type", "args"])
};