admin管理员组文章数量:1332389
I want to modify console.log
so that it saves everything that the application outputs to the mand line using console.log
.
I have tried
var log = console.log;
console.log = function () {
// fs.appendFile('log.txt ..
log.apply(log, arguments);
}
But it gives me the error
Illegal invocation
I want to modify console.log
so that it saves everything that the application outputs to the mand line using console.log
.
I have tried
var log = console.log;
console.log = function () {
// fs.appendFile('log.txt ..
log.apply(log, arguments);
}
But it gives me the error
Illegal invocation
Share
Improve this question
asked Jun 11, 2015 at 18:44
afonso-botafonso-bot
351 silver badge4 bronze badges
1 Answer
Reset to default 10The first arguments to apply
is what this
will refer to. To mimic a call to console.log()
, you have to pass console
, not the function itself:
var log = console.log;
log.apply(console, arguments);
// log.apply(this, arguments); would work as well
本文标签: javascriptModify consolelogStack Overflow
版权声明:本文标题:javascript - Modify console.log - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742289379a2447514.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论