From d1b0e6d66d2569e659cbf8e97352ea8bfb521bc9 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Wed, 6 May 2015 12:34:58 -0300 Subject: [PATCH] See #296. Add package option for setting logger level --- src/beautify.coffee | 5 +++++ src/logger.coffee | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/beautify.coffee b/src/beautify.coffee index 4a632c2..05b2f66 100644 --- a/src/beautify.coffee +++ b/src/beautify.coffee @@ -344,6 +344,11 @@ plugin.config = _.merge( type: 'string' default: "" 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: type: 'boolean' default: false diff --git a/src/logger.coffee b/src/logger.coffee index 92d7a19..db63e5e 100644 --- a/src/logger.coffee +++ b/src/logger.coffee @@ -12,11 +12,24 @@ module.exports = do -> writable = new stream.Writable({ write: (chunk, encoding, next) -> msg = chunk.toString() - # console.log msg + # console.log(msg) emitter.emit('logging', msg) next() }) + levels = { + silly: 0, + input: 1, + verbose: 2, + prompt: 3, + debug: 4, + info: 5, + data: 6, + help: 7, + warn: 8, + error: 9 + } + return (label) -> transport = new (winston.transports.File)({ label: label @@ -34,6 +47,16 @@ module.exports = do -> 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 loggerMethods = ['silly','debug','verbose','info','warn','error'] logger = {}