不要怂,就是干,撸起袖子干!

Commit 744c5d86 by Ken Perkins

Adding the ability to provide a custom logging function in lieu of console.log

1 parent 3bd86036
......@@ -23,10 +23,11 @@ module.exports = (function() {
bindClient.call(this)
if(this.options.logging)
if((this.options.logging) && (this.options.customLogger))
this.options.customLogger('Executing: ' + this.sql)
else if (this.options.logging)
console.log('Executing: ' + this.sql)
this.client.query(this.sql, function(err, results, fields) {
self.emit('sql', self.sql)
err ? onFailure.call(self, err) : onSuccess.call(self, results, fields)
......
......@@ -17,7 +17,9 @@ module.exports = (function() {
this.sql = sql
if(this.options.logging)
if((this.options.logging) && (this.options.customLogger))
this.options.customLogger('Executing: ' + this.sql)
else if(this.options.logging)
console.log('Executing: ' + this.sql)
this.database.serialize(function() {
......
......@@ -46,11 +46,15 @@ module.exports = (function() {
migrations.forEach(function(migration) {
chainer.add(migration, 'execute', [options], {
before: function(migration) {
if(self.options.logging)
if((self.options.logging) && (self.options.customLogger))
self.options.customLogger('Executing migration: ' + migration.filename)
else if(self.options.logging)
console.log('Executing migration: ' + migration.filename)
},
after: function(migration) {
if(self.options.logging)
if ((self.options.logging) && (self.options.customLogger))
self.options.customLogger('Executed migration: ' + migration.filename)
else if (self.options.logging)
console.log('Executed migration: ' + migration.filename)
},
success: function(migration, callback) {
......
......@@ -72,7 +72,9 @@ module.exports = (function() {
Sequelize.prototype.query = function(sql, callee, options) {
options = Utils._.extend(Utils._.clone(this.options.query), options || {})
options = Utils._.extend(options, {
logging: this.options.hasOwnProperty('logging') ? this.options.logging : true
logging: this.options.hasOwnProperty('logging') ? this.options.logging : true,
customLogger: this.options.hasOwnProperty('customLogger') &&
typeof(this.options.customLogger) === 'function' ? this.options.customLogger : undefined
})
return this.connectorManager.query(sql, callee, options)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!