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 f7c9be39
authored
Mar 29, 2014
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't depend on winston
1 parent
04fdd411
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
96 deletions
lib/sequelize.js
test/sequelize/log.test.js
lib/sequelize.js
View file @
f7c9be3
...
...
@@ -494,44 +494,16 @@ module.exports = (function() {
return
transaction
}
Object
.
defineProperty
(
Sequelize
.
prototype
,
'logger'
,
{
get
:
function
()
{
if
(
!
this
.
_logger
)
{
if
(
Sequelize
.
Utils
.
isHash
(
this
.
options
.
logging
))
{
this
.
_logger
=
new
winston
.
Logger
(
this
.
options
.
logging
)
}
else
{
this
.
_logger
=
winston
}
}
Sequelize
.
prototype
.
log
=
function
()
{
var
args
=
[].
slice
.
call
(
arguments
)
return
this
.
_logger
}
})
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
)
if
(
this
.
options
.
logging
===
true
)
{
console
.
log
(
'DEPRECATION WARNING: The logging-option should be either a function or false. Default: console.log'
)
this
.
options
.
logging
=
console
.
log
}
if
((
typeof
this
.
options
.
logging
===
'function'
)
&&
(
this
.
options
.
logging
!=
console
.
log
))
{
this
.
options
.
logging
.
apply
(
null
,
args
.
slice
(
1
))
}
else
{
this
.
logger
.
log
.
apply
(
this
.
logger
,
args
)
}
this
.
options
.
logging
.
apply
(
null
,
args
)
}
}
...
...
test/sequelize/log.test.js
View file @
f7c9be3
...
...
@@ -15,60 +15,45 @@ 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
()
this
.
sequelize
=
new
Support
.
Sequelize
(
'db'
,
'user'
,
'pw'
,
{
logging
:
false
})
this
.
spy
=
sinon
.
spy
(
console
.
log
)
})
it
(
"does not call the log method of the logger"
,
function
()
{
this
.
loggerMock
.
expects
(
"log"
).
never
()
this
.
sequelize
.
log
()
expect
(
this
.
spy
.
calledOnce
).
to
.
be
.
false
})
})
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
()
this
.
sequelize
=
new
Support
.
Sequelize
(
'db'
,
'user'
,
'pw'
)
this
.
spy
=
sinon
.
spy
(
console
.
log
)
})
describe
(
"called with no arguments"
,
function
()
{
it
(
'calls the log method'
,
function
()
{
this
.
loggerMock
.
expects
(
"log"
).
once
()
this
.
sequelize
.
log
()
expect
(
this
.
spy
.
calledOnce
).
to
.
be
.
false
})
it
(
'logs an empty string as info event'
,
function
()
{
this
.
loggerMock
.
expects
(
"log"
).
withArgs
(
'info'
,
''
).
once
()
this
.
sequelize
.
log
()
expect
(
this
.
spy
.
withArgs
(
''
).
calledOnce
).
to
.
be
.
false
})
})
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'
)
expect
(
this
.
spy
.
withArgs
(
'my message'
).
calledOnce
).
to
.
be
.
false
})
})
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
})
it
(
"passes the arguments to the logger"
,
function
()
{
this
.
sequelize
.
log
(
'error'
,
'my message'
,
1
,
{
a
:
1
})
expect
(
this
.
spy
.
withArgs
(
'error'
,
'my message'
,
1
,
{
a
:
1
}).
calledOnce
).
to
.
be
.
false
})
})
})
...
...
@@ -84,42 +69,5 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
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
)
})
})
})
})
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