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

Commit cd364aad by Sascha Depold

Allow passing of winston options

1 parent fe4eef85
Showing with 49 additions and 1 deletions
...@@ -496,7 +496,15 @@ module.exports = (function() { ...@@ -496,7 +496,15 @@ module.exports = (function() {
Object.defineProperty(Sequelize.prototype, 'logger', { Object.defineProperty(Sequelize.prototype, 'logger', {
get: function() { get: function() {
return (this._logger = (this._logger || winston)) if (!this._logger) {
if (Sequelize.Utils.isHash(this.options.logging)) {
this._logger = new winston.Logger(this.options.logging)
} else {
this._logger = winston
}
}
return this._logger
} }
}) })
......
var chai = require('chai') var chai = require('chai')
, sinonChai = require("sinon-chai") , sinonChai = require("sinon-chai")
, sinon = require('sinon') , sinon = require('sinon')
, winston = require('winston')
, fs = require('fs')
, path = require('path')
, expect = chai.expect , expect = chai.expect
, assert = chai.assert , assert = chai.assert
, Support = require(__dirname + '/../support') , Support = require(__dirname + '/../support')
...@@ -81,5 +84,42 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { ...@@ -81,5 +84,42 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
expect(this.spy.calledOnce).to.be.true expect(this.spy.calledOnce).to.be.true
}) })
}) })
describe("with custom winston options", function() {
beforeEach(function() {
this.logFile = path.normalize(__dirname + '/../tmp/sequelize.log')
if (fs.existsSync(this.logFile)) {
fs.unlinkSync(this.logFile)
}
this.spy = sinon.spy()
this.sequelize = new Support.Sequelize('db', 'user', 'pw', {
logging: {
transports: [
new winston.transports.File({ filename: this.logFile })
]
}
})
})
afterEach(function() {
if (fs.existsSync(this.logFile)) {
fs.unlinkSync(this.logFile)
}
})
it("calls the custom logger method", function(done) {
var self = this
expect(fs.existsSync(this.logFile)).to.be.false
this.sequelize.log('om nom')
setTimeout(function() {
expect(fs.existsSync(self.logFile)).to.be.true
done()
}, 100)
})
})
}) })
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!