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

Commit 5e45b82b by Sascha Depold

Merge pull request #153 from kenperkins/master

Add override for logging option to provide custom logging function
2 parents 3bd86036 89441cb1
...@@ -7,7 +7,7 @@ module.exports = (function() { ...@@ -7,7 +7,7 @@ module.exports = (function() {
this.client = client this.client = client
this.callee = callee this.callee = callee
this.options = Utils._.extend({ this.options = Utils._.extend({
logging: true, logging: console.log,
plain: false, plain: false,
raw: false raw: false
}, options || {}) }, options || {})
...@@ -23,9 +23,8 @@ module.exports = (function() { ...@@ -23,9 +23,8 @@ module.exports = (function() {
bindClient.call(this) bindClient.call(this)
if(this.options.logging) if(this.options.logging !== false)
console.log('Executing: ' + this.sql) this.options.logging('Executing: ' + this.sql)
this.client.query(this.sql, function(err, results, fields) { this.client.query(this.sql, function(err, results, fields) {
self.emit('sql', self.sql) self.emit('sql', self.sql)
......
...@@ -5,7 +5,7 @@ module.exports = (function() { ...@@ -5,7 +5,7 @@ module.exports = (function() {
this.database = database this.database = database
this.callee = callee this.callee = callee
this.options = Utils._.extend({ this.options = Utils._.extend({
logging: true, logging: console.log,
plain: false, plain: false,
raw: false raw: false
}, options || {}) }, options || {})
...@@ -17,8 +17,8 @@ module.exports = (function() { ...@@ -17,8 +17,8 @@ module.exports = (function() {
this.sql = sql this.sql = sql
if(this.options.logging) if(this.options.logging !== false)
console.log('Executing: ' + this.sql) this.options.logging('Executing: ' + this.sql)
this.database.serialize(function() { this.database.serialize(function() {
var isInsertCommand = (self.sql.toLowerCase().indexOf('insert') == 0) var isInsertCommand = (self.sql.toLowerCase().indexOf('insert') == 0)
......
...@@ -13,7 +13,7 @@ module.exports = (function() { ...@@ -13,7 +13,7 @@ module.exports = (function() {
path: __dirname + '/../migrations', path: __dirname + '/../migrations',
from: null, from: null,
to: null, to: null,
logging: true logging: console.log
}, options || {}) }, options || {})
} }
...@@ -46,12 +46,12 @@ module.exports = (function() { ...@@ -46,12 +46,12 @@ module.exports = (function() {
migrations.forEach(function(migration) { migrations.forEach(function(migration) {
chainer.add(migration, 'execute', [options], { chainer.add(migration, 'execute', [options], {
before: function(migration) { before: function(migration) {
if(self.options.logging) if(self.options.logging !== false)
console.log('Executing migration: ' + migration.filename) self.options.logging('Executing migration: ' + migration.filename)
}, },
after: function(migration) { after: function(migration) {
if(self.options.logging) if(self.options.logging !== false)
console.log('Executed migration: ' + migration.filename) self.options.logging('Executed migration: ' + migration.filename)
}, },
success: function(migration, callback) { success: function(migration, callback) {
if(options.method == 'down') if(options.method == 'down')
......
...@@ -72,7 +72,7 @@ module.exports = (function() { ...@@ -72,7 +72,7 @@ module.exports = (function() {
Sequelize.prototype.query = function(sql, callee, options) { Sequelize.prototype.query = function(sql, callee, options) {
options = Utils._.extend(Utils._.clone(this.options.query), options || {}) options = Utils._.extend(Utils._.clone(this.options.query), options || {})
options = Utils._.extend(options, { options = Utils._.extend(options, {
logging: this.options.hasOwnProperty('logging') ? this.options.logging : true logging: this.options.hasOwnProperty('logging') ? this.options.logging : console.log
}) })
return this.connectorManager.query(sql, callee, options) 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!