Skip to content

Commit 1790794

Browse files
committed
fix: make logger to be singleton
1 parent 32310cb commit 1790794

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

lib/debug.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const get = require("lodash.get");
2+
const getLogger = require("./getLogger");
23

34
let opts;
45

56
const createDebugger = prefix => (...input) => {
6-
const getLogger = require("./getLogger");
77
const logger = getLogger({ stdout: process.stdout, stderr: process.stderr });
88

99
// if (get(opts, prefix || "")) {
10-
console.log(...input);
11-
return logger.log(...input);
10+
console.log(prefix, ...input);
11+
return logger.log(prefix, ...input);
1212
// }
1313
};
1414

lib/getLogger.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { Signale } = require("signale");
2+
const once = require("lodash.once");
23

34
/**
45
* Return a new Signale instance.
@@ -25,4 +26,4 @@ function getLogger({ stdout, stderr }) {
2526
}
2627

2728
// Exports.
28-
module.exports = getLogger;
29+
module.exports = once(getLogger);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"get-stream": "^5.1.0",
5656
"git-log-parser": "^1.2.0",
5757
"lodash.get": "^4.4.2",
58+
"lodash.once": "^4.1.1",
5859
"lodash.pairs": "^3.0.1",
5960
"lodash.set": "^4.3.2",
6061
"meow": "^6.0.1",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4775,6 +4775,11 @@ lodash.keys@^3.0.0:
47754775
lodash.isarguments "^3.0.0"
47764776
lodash.isarray "^3.0.0"
47774777

4778+
lodash.once@^4.1.1:
4779+
version "4.1.1"
4780+
resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac"
4781+
integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=
4782+
47784783
lodash.pairs@^3.0.1:
47794784
version "3.0.1"
47804785
resolved "https://registry.yarnpkg.com/lodash.pairs/-/lodash.pairs-3.0.1.tgz#bbe08d5786eeeaa09a15c91ebf0dcb7d2be326a9"

0 commit comments

Comments
 (0)