Skip to content

Commit

Permalink
added string interpolation support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Nov 17, 2015
1 parent ab7fd74 commit f3c7623
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 13 deletions.
94 changes: 84 additions & 10 deletions example.js
Original file line number Diff line number Diff line change
@@ -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);
11 changes: 9 additions & 2 deletions lib/Acho.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

chalk = require 'chalk'
DEFAULT = require './Default'
format = require 'format-util'

module.exports = class Acho

Expand All @@ -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
Expand All @@ -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

3 changes: 2 additions & 1 deletion lib/Default.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ module.exports =
messageType + message

GENERATE_TYPE_MESSAGE: (type) ->
(message) =>
(message...) =>
message = @_format message
@transport @generateMessage type, message
this

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down

0 comments on commit f3c7623

Please sign in to comment.