Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 8d02f36b
authored
Mar 28, 2014
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add log method to sequelize
1 parent
6dbdde03
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
3 deletions
lib/sequelize.js
package.json
test/sequelize/log.test.js
lib/sequelize.js
View file @
8d02f36
...
...
@@ -10,6 +10,7 @@ var url = require("url")
,
TransactionManager
=
require
(
'./transaction-manager'
)
,
QueryTypes
=
require
(
'./query-types'
)
,
sequelizeErrors
=
require
(
'./errors'
)
,
winston
=
require
(
'winston'
)
module
.
exports
=
(
function
()
{
/**
...
...
@@ -406,7 +407,7 @@ module.exports = (function() {
self
.
daoFactoryManager
.
forEachDAO
(
function
(
dao
)
{
if
(
dao
)
{
chainer
.
add
(
dao
,
'drop'
,
[
options
])
chainer
.
add
(
dao
,
'drop'
,
[
options
])
}
},
{
reverse
:
false
})
...
...
@@ -493,5 +494,34 @@ module.exports = (function() {
return
transaction
}
Object
.
defineProperty
(
Sequelize
.
prototype
,
'logger'
,
{
get
:
function
()
{
return
(
this
.
_logger
=
(
this
.
_logger
||
winston
))
}
})
Sequelize
.
prototype
.
log
=
function
(
typeOrMessage
)
{
if
(
this
.
options
.
logging
)
{
var
args
=
[]
if
(
arguments
.
length
===
0
)
{
// No arguments have been passed. Log an empty string.
args
.
push
(
'info'
)
args
.
push
(
''
)
}
else
if
(
arguments
.
length
===
1
)
{
// Only one argument has been passed.
// Use the default type and treat the argument as message.
args
.
push
(
'info'
)
args
.
push
(
typeOrMessage
)
}
else
{
// There have been more than one passed arguments.
// Use them as arguments for winston.
args
=
[].
slice
.
call
(
arguments
)
}
this
.
logger
.
log
.
apply
(
this
.
logger
,
args
)
}
}
return
Sequelize
})()
package.json
View file @
8d02f36
...
...
@@ -52,7 +52,8 @@
"sql"
:
"~0.35.0"
,
"circular-json"
:
"~0.1.5"
,
"bluebird"
:
"~1.0.0"
,
"node-uuid"
:
"~1.4.1"
"node-uuid"
:
"~1.4.1"
,
"winston"
:
"~0.7.3"
},
"devDependencies"
:
{
"sqlite3"
:
"~2.1.12"
,
...
...
@@ -69,7 +70,8 @@
"istanbul"
:
"~0.1.45"
,
"coveralls"
:
"~2.7.1"
,
"async"
:
"~0.2.10"
,
"coffee-script"
:
"~1.7.1"
"coffee-script"
:
"~1.7.1"
,
"sinon-chai"
:
"~2.5.0"
},
"keywords"
:
[
"mysql"
,
...
...
test/sequelize/log.test.js
0 → 100644
View file @
8d02f36
var
chai
=
require
(
'chai'
)
,
sinonChai
=
require
(
"sinon-chai"
)
,
sinon
=
require
(
'sinon'
)
,
expect
=
chai
.
expect
,
assert
=
chai
.
assert
,
Support
=
require
(
__dirname
+
'/../support'
)
chai
.
use
(
sinonChai
)
chai
.
config
.
includeStack
=
true
describe
(
Support
.
getTestDialectTeaser
(
"Sequelize"
),
function
()
{
describe
(
'log'
,
function
()
{
describe
(
"with disabled logging"
,
function
()
{
beforeEach
(
function
()
{
this
.
sequelize
=
new
Support
.
Sequelize
(
'db'
,
'user'
,
'pw'
,
{
logging
:
false
})
this
.
loggerMock
=
sinon
.
mock
(
this
.
sequelize
.
logger
)
})
afterEach
(
function
()
{
this
.
loggerMock
.
verify
()
})
it
(
"does not call the log method of the logger"
,
function
()
{
this
.
loggerMock
.
expects
(
"log"
).
never
()
this
.
sequelize
.
log
()
})
})
describe
(
'with default logging options'
,
function
()
{
beforeEach
(
function
()
{
this
.
sequelize
=
new
Support
.
Sequelize
(
'db'
,
'user'
,
'pw'
)
this
.
loggerMock
=
sinon
.
mock
(
this
.
sequelize
.
logger
)
})
afterEach
(
function
()
{
this
.
loggerMock
.
verify
()
})
describe
(
"called with no arguments"
,
function
()
{
it
(
'calls the log method'
,
function
()
{
this
.
loggerMock
.
expects
(
"log"
).
once
()
this
.
sequelize
.
log
()
})
it
(
'logs an empty string as info event'
,
function
()
{
this
.
loggerMock
.
expects
(
"log"
).
withArgs
(
'info'
,
''
).
once
()
this
.
sequelize
.
log
()
})
})
describe
(
"called with one argument"
,
function
()
{
it
(
'logs the passed string as info event'
,
function
()
{
this
.
loggerMock
.
expects
(
"log"
).
withArgs
(
'info'
,
'my message'
).
once
()
this
.
sequelize
.
log
(
'my message'
)
})
})
describe
(
"called with two arguments"
,
function
()
{
it
(
"uses the first argument as event name and the second as message"
,
function
()
{
this
.
loggerMock
.
expects
(
"log"
).
withArgs
(
'error'
,
'my message'
)
this
.
sequelize
.
log
(
'error'
,
'my message'
)
})
})
describe
(
"called with more than two arguments"
,
function
()
{
it
(
"uses the first argument as event name and passes the others to the logger"
,
function
()
{
this
.
loggerMock
.
expects
(
"log"
).
withArgs
(
'error'
,
'my message'
,
1
,
{
a
:
1
})
this
.
sequelize
.
log
(
'error'
,
'my message'
,
1
,
{
a
:
1
})
})
})
})
})
})
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment