Last change
on this file since 84d0fbb was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const SyncBailHook = require("tapable/lib/SyncBailHook");
|
---|
| 9 | const { Logger } = require("./Logger");
|
---|
| 10 | const createConsoleLogger = require("./createConsoleLogger");
|
---|
| 11 |
|
---|
| 12 | /** @type {createConsoleLogger.LoggerOptions} */
|
---|
| 13 | let currentDefaultLoggerOptions = {
|
---|
| 14 | level: "info",
|
---|
| 15 | debug: false,
|
---|
| 16 | console
|
---|
| 17 | };
|
---|
| 18 | let currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
|
---|
| 19 |
|
---|
| 20 | /**
|
---|
| 21 | * @param {string} name name of the logger
|
---|
| 22 | * @returns {Logger} a logger
|
---|
| 23 | */
|
---|
| 24 | exports.getLogger = name => {
|
---|
| 25 | return new Logger(
|
---|
| 26 | (type, args) => {
|
---|
| 27 | if (exports.hooks.log.call(name, type, args) === undefined) {
|
---|
| 28 | currentDefaultLogger(name, type, args);
|
---|
| 29 | }
|
---|
| 30 | },
|
---|
| 31 | childName => exports.getLogger(`${name}/${childName}`)
|
---|
| 32 | );
|
---|
| 33 | };
|
---|
| 34 |
|
---|
| 35 | /**
|
---|
| 36 | * @param {createConsoleLogger.LoggerOptions} options new options, merge with old options
|
---|
| 37 | * @returns {void}
|
---|
| 38 | */
|
---|
| 39 | exports.configureDefaultLogger = options => {
|
---|
| 40 | Object.assign(currentDefaultLoggerOptions, options);
|
---|
| 41 | currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
|
---|
| 42 | };
|
---|
| 43 |
|
---|
| 44 | exports.hooks = {
|
---|
| 45 | log: new SyncBailHook(["origin", "type", "args"])
|
---|
| 46 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.