diff --git a/example.js b/example.js index e3ac20d..df9e177 100644 --- a/example.js +++ b/example.js @@ -1,14 +1,88 @@ +'use strict'; + +require('date-utils'); var Acho = require('./index.js'); +var setDateout = require('set-dateout'); + +var base = new Acho({ + align: true +}); + +var diff = new Acho({ + diff: true +}); + +var label = new Acho({ + align: false, + keyword: 'worker#1' +}); + +var colors = new Acho({ + color: false +}); -var acho = new Acho({ - level: 'silly', - color: true +var visit = new Acho({ + keyword: 'visit' }); -acho.error('error message'); -acho.warning('warning message'); -acho.success('success message'); -acho.info('info message'); -acho.verbose('verbose message'); -acho.debug('debug message'); -acho.silly('silly message'); +var getStep = (function() { + var start = 0; + return function(value) { + if (value) start += value; + else ++start; + return start; + }; +})(); + +var messageTimeout = (function() { + return function(level, message, logger, time) { + setDateout(function() { + logger[level](message); + }, new Date().add({seconds: getStep(0.8)})); + }; +})(); + +var lineBreakTimeout = (function() { + return function(time) { + setDateout(function() { + console.log(); + }, new Date().add({seconds: getStep(time || 0.2)})); + }; +})(); + +messageTimeout('info', 'Simple', base); +messageTimeout('success', 'Tiny', base); +messageTimeout('verbose', 'Customizable', base); +messageTimeout('silly', 'Logger for NodeJS and Browser', base); +messageTimeout('warn', 'in less than...', base); +messageTimeout('error', '10KB!.', base); + +lineBreakTimeout(1); + +messageTimeout('info', 'Do you wanna to know more?', base); + +lineBreakTimeout(); + +messageTimeout('success', 'support diff', diff); +messageTimeout('success', 'between messages', diff); + +lineBreakTimeout(); + +messageTimeout('warn', 'adapt the logger label', label); +messageTimeout('warn', 'easily', label); + +lineBreakTimeout(); + +messageTimeout('error', 'automatically color disabled', colors); +messageTimeout('error', 'under production', colors); + +lineBreakTimeout(); + +messageTimeout('silly', 'and more more more...', base); +messageTimeout('debug', 'string interpolation', base); +messageTimeout('verbose', 'logs align', base); +messageTimeout('info', 'custom levels and transports', base); + +lineBreakTimeout(); + +messageTimeout('success', 'https://github.com/Kikobeats/acho', visit); diff --git a/lib/Acho.coffee b/lib/Acho.coffee index f4d32da..0d75793 100644 --- a/lib/Acho.coffee +++ b/lib/Acho.coffee @@ -2,6 +2,7 @@ chalk = require 'chalk' DEFAULT = require './Default' +format = require 'format-util' module.exports = class Acho @@ -26,11 +27,13 @@ module.exports = class Acho messages this - push: (type, message) -> + push: (type, messages...) -> + message = @_format messages @messages[type].push message this - add: (type, message) -> + add: (type, messages...) -> + message = @_format messages @[type] message @push type, message this @@ -46,3 +49,7 @@ module.exports = class Acho return true if @level is DEFAULT.UNMUTED return false if @level is DEFAULT.MUTED @types[type].level <= @types[@level].level + + _format: (messages) -> + format.apply null, messages + diff --git a/lib/Default.coffee b/lib/Default.coffee index 3873795..325d7e0 100644 --- a/lib/Default.coffee +++ b/lib/Default.coffee @@ -38,7 +38,8 @@ module.exports = messageType + message GENERATE_TYPE_MESSAGE: (type) -> - (message) => + (message...) => + message = @_format message @transport @generateMessage type, message this diff --git a/package.json b/package.json index b697739..83ed683 100644 --- a/package.json +++ b/package.json @@ -21,16 +21,19 @@ "dependencies": { "chalk": "*", "coffee-script": "*", + "format-util": "*", "pretty-ms": "*" }, "devDependencies": { "browserify": "*", "coffeeify": "*", + "date-utils": "*", "gulp": "*", "gulp-header": "*", "gulp-uglify": "*", "gulp-util": "*", "mocha": "*", + "set-dateout": "*", "should": "*", "titleize": "*", "vinyl-buffer": "*",