Initial commit (from f5274cbdce4ae7c9e4b937dcdf95ac70ae436d5f)
This commit is contained in:
commit
28ccc3db2d
13974 changed files with 2618436 additions and 0 deletions
46
node_modules/console-log-level/index.js
generated
vendored
Normal file
46
node_modules/console-log-level/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
'use strict'
|
||||
|
||||
var util = require('util')
|
||||
|
||||
var levels = ['trace', 'debug', 'info', 'warn', 'error', 'fatal']
|
||||
var noop = function () {}
|
||||
|
||||
module.exports = function (opts) {
|
||||
opts = opts || {}
|
||||
opts.level = opts.level || 'info'
|
||||
|
||||
var logger = {}
|
||||
|
||||
var shouldLog = function (level) {
|
||||
return levels.indexOf(level) >= levels.indexOf(opts.level)
|
||||
}
|
||||
|
||||
levels.forEach(function (level) {
|
||||
logger[level] = shouldLog(level) ? log : noop
|
||||
|
||||
function log () {
|
||||
var prefix = opts.prefix
|
||||
var normalizedLevel
|
||||
|
||||
if (opts.stderr) {
|
||||
normalizedLevel = 'error'
|
||||
} else {
|
||||
switch (level) {
|
||||
case 'trace': normalizedLevel = 'info'; break
|
||||
case 'debug': normalizedLevel = 'info'; break
|
||||
case 'fatal': normalizedLevel = 'error'; break
|
||||
default: normalizedLevel = level
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix) {
|
||||
if (typeof prefix === 'function') prefix = prefix(level)
|
||||
arguments[0] = util.format(prefix, arguments[0])
|
||||
}
|
||||
|
||||
console[normalizedLevel](util.format.apply(util, arguments))
|
||||
}
|
||||
})
|
||||
|
||||
return logger
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue