Skip to content

Commit

Permalink
Forcing color output.
Browse files Browse the repository at this point in the history
  • Loading branch information
wbyoung committed Jun 21, 2014
1 parent 921bdbb commit e0e56db
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

var chalk = require('chalk');

module.exports = function(knex, options) {
var opts = options || {};

if (opts.forceColor) {
var colored = function(fn) {
return function() {
var enabled = chalk.enabled;
chalk.enabled = true;
fn.apply(this, arguments);
chalk.enabled = enabled;
}
};

module.exports = function(knex, options) {
var opts = options || {};

return function(req, res, next) {

Expand All @@ -26,7 +31,7 @@ module.exports = function(knex, options) {
});
};

var logQuery = function() {
var logQuery = colored(function() {
res.removeListener('finish', logQuery);
res.removeListener('close', logQuery);
knex.client.removeListener('query', watchQuery);
Expand All @@ -39,7 +44,7 @@ module.exports = function(knex, options) {
chalk.cyan('{' + query.bindings.join(', ') + '}'),
chalk.magenta(query.duration + 'ms'));
});
};
});

knex.client.on('query', watchQuery);
res.on('finish', logQuery);
Expand Down

0 comments on commit e0e56db

Please sign in to comment.