See #296. Add package option for setting logger level
This commit is contained in:
parent
52d67cd0f3
commit
d1b0e6d66d
|
@ -344,6 +344,11 @@ plugin.config = _.merge(
|
||||||
type: 'string'
|
type: 'string'
|
||||||
default: ""
|
default: ""
|
||||||
description: "Unique identifier for this user for tracking usage analytics"
|
description: "Unique identifier for this user for tracking usage analytics"
|
||||||
|
_loggerLevel:
|
||||||
|
type: 'string'
|
||||||
|
default: 'warn'
|
||||||
|
description: 'Set the level for the logger'
|
||||||
|
enum: ['verbose','debug','info','warn','error']
|
||||||
beautifyOnSave:
|
beautifyOnSave:
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
default: false
|
default: false
|
||||||
|
|
|
@ -12,11 +12,24 @@ module.exports = do ->
|
||||||
writable = new stream.Writable({
|
writable = new stream.Writable({
|
||||||
write: (chunk, encoding, next) ->
|
write: (chunk, encoding, next) ->
|
||||||
msg = chunk.toString()
|
msg = chunk.toString()
|
||||||
# console.log msg
|
# console.log(msg)
|
||||||
emitter.emit('logging', msg)
|
emitter.emit('logging', msg)
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
levels = {
|
||||||
|
silly: 0,
|
||||||
|
input: 1,
|
||||||
|
verbose: 2,
|
||||||
|
prompt: 3,
|
||||||
|
debug: 4,
|
||||||
|
info: 5,
|
||||||
|
data: 6,
|
||||||
|
help: 7,
|
||||||
|
warn: 8,
|
||||||
|
error: 9
|
||||||
|
}
|
||||||
|
|
||||||
return (label) ->
|
return (label) ->
|
||||||
transport = new (winston.transports.File)({
|
transport = new (winston.transports.File)({
|
||||||
label: label
|
label: label
|
||||||
|
@ -34,6 +47,16 @@ module.exports = do ->
|
||||||
transport
|
transport
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
wlogger.on('logging', (transport, level, msg, meta)->
|
||||||
|
loggerLevel = atom.config.get('atom-beautify._loggerLevel')
|
||||||
|
# console.log('logging', loggerLevel, arguments)
|
||||||
|
loggerLevelNum = levels[loggerLevel]
|
||||||
|
levelNum = levels[level]
|
||||||
|
if loggerLevelNum <= levelNum
|
||||||
|
path = require('path')
|
||||||
|
label = path.basename(transport.label)
|
||||||
|
console.log("#{label} [#{level}]: #{msg}", meta)
|
||||||
|
)
|
||||||
# Export logger methods
|
# Export logger methods
|
||||||
loggerMethods = ['silly','debug','verbose','info','warn','error']
|
loggerMethods = ['silly','debug','verbose','info','warn','error']
|
||||||
logger = {}
|
logger = {}
|
||||||
|
|
Loading…
Reference in New Issue