-
Notifications
You must be signed in to change notification settings - Fork 2
/
log.js
34 lines (29 loc) · 864 Bytes
/
log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
/**
* @typedef {(...args: any) => void} LogFunction
*/
/**
* @typedef {ValidLogger | console | undefined} AbstractLoggerOptions
*/
/**
* @typedef {object} ValidLogger
* @property {LogFunction} trace
* @property {LogFunction} debug
* @property {LogFunction} info
* @property {LogFunction} warn
* @property {LogFunction} error
* @property {LogFunction} fatal
*/
const NoopLog = require('nooplog');
const utils = require('./utils');
/**
* Returns an abstract logger which enables adding logging to modules without adding a dependency to a full log library.
* @param {AbstractLoggerOptions} logger
* @returns {ValidLogger}
*/
module.exports = function abslog(logger) {
if (Object.is(logger, console)) {
return Object.create(utils.consoleLogger);
}
return utils.validateLogger(logger) ? logger : new NoopLog();
};