admin管理员组文章数量:1417483
I want to log the console logs whether the expect failing or any exception ing into the log file. How can i do that without using try and catch. In LOG4j for java there is rootlogger which automatically logs all the system information logs into the file. Can same be done for log4JS for javascript
log4js.configure({
appenders: [
{
type: "clustered",
appenders: [
{
type: "dateFile",
filename: "log/access.log",
pattern: "-yyyy-MM-dd",
category: "http"
},
{
type: "file",
filename: "log/app.log",
maxLogSize: 10485760,
numBackups: 3
},
{
type: "logLevelFilter",
level: "ERROR",
appender: {
type: "file",
filename: "log/errors.log"
}
}
]
}
]
})
I want to log the console logs whether the expect failing or any exception ing into the log file. How can i do that without using try and catch. In LOG4j for java there is rootlogger which automatically logs all the system information logs into the file. Can same be done for log4JS for javascript
log4js.configure({
appenders: [
{
type: "clustered",
appenders: [
{
type: "dateFile",
filename: "log/access.log",
pattern: "-yyyy-MM-dd",
category: "http"
},
{
type: "file",
filename: "log/app.log",
maxLogSize: 10485760,
numBackups: 3
},
{
type: "logLevelFilter",
level: "ERROR",
appender: {
type: "file",
filename: "log/errors.log"
}
}
]
}
]
})
Share
Improve this question
edited Jun 20, 2017 at 8:19
user8088868
asked Jun 20, 2017 at 6:03
anuvrat singhanuvrat singh
4211 gold badge8 silver badges20 bronze badges
1 Answer
Reset to default 5You can override the default console.log
functions to point to your logger e.g.
const logger = log4js.getLogger('cheese');
console.log = (msg) => logger.trace(msg);
You can do similar things for other functions e.g. console.debug
etc.
That said. You would be better off calling logger
explicitly.
本文标签: javascriptHow to log the Console logs into the file using log4jsStack Overflow
版权声明:本文标题:javascript - How to log the Console logs into the file using log4js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745267763a2650706.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论