我有一个节点应用程序,其中使用Winstonjs作为记录器。在我的记录器中,我有一个特定的部分用于记录如下异常:
<div class="page-header header-filter">
<div class="container">
<div class="row">
<div class="col-md-8 ml-auto mr-auto">
<div class="brand">
<h1> Some smart text </h1>
<h3 class="title"> Start the Development With A Badass Bootstrap 4 UI Kit inspired by Material Design. </h3>
</div>
</div>
</div>
</div>
</div>
.page-header {
height: 100vh;
color: #fff;
background-position: 50%;
background-size: cover;
background-image: url(../img/ggg.jpg);
display: flex;
align-items: center;
}
.brand {
text-align: center;
}
.header-filter::after {
position: absolute;
z-index: 1;
width: 100%;
height: 100%;
display: block;
left: 0;
top: 0;
content: "";
}
.header-filter::after {
background: rgba(132,13,121,.88);
background: linear-gradient(45deg,rgba(132,13,121,.88),rgba(208,44,180,.31));
background: -webkit-linear-gradient(135deg,rgba(132,13,121,.88),rgba(208,44,180,.31));
}
因此,任何异常都应同时记录在const myFormat = winston.format.printf(info => {
return `${info.timestamp} ${info.level}: ${info.message}`;
});
const logger = winston.createLogger({
level: "debug",
format: winston.format.combine(winston.format.timestamp(), myFormat), // winston.format.json(),
transports: [
new winston.transports.File({filename: "logs/error.log", level: 'error'}),
new winston.transports.File({filename: 'logs/combined.log'}),
],
exceptionHandlers: [
new winston.transports.File({ filename: 'logs/exceptions.log' }),
new winston.transports.File({ filename: 'logs/combined.log' })
],
exitOnError: false
});
和logs/combined.log
中。
运行程序时,我有时有时会在我的STDOUT中收到以下错误,该错误来自Sequelizejs,我曾用它写入我的MySQL数据库。
logs/exceptions.log
此错误仅在stdout中显示(手动运行程序时),在Unhandled rejection TimeoutError: ResourceRequest timed out
at ResourceRequest._fireTimeout (/root/mmjs/node_modules/generic-pool/lib/ResourceRequest.js:62:17)
at Timeout.bound (/root/mmjs/node_modules/generic-pool/lib/ResourceRequest.js:8:15)
at ontimeout (timers.js:424:11)
at tryOnTimeout (timers.js:288:5)
at listOnTimeout (timers.js:251:5)
at Timer.processTimers (timers.js:211:10)
或combined.log
中均不显示。可能是因为这是错误而不是例外。我不确定如何正确地记录它。
(我想我可以wrap my whole code in a try/catch,但是我想还有更好的方法.. :-))
有人可以帮我记录下此错误和类似的未捕获错误吗?
答案 0 :(得分:1)
过程是指节点。尝试在index.js中添加unhandledRejection检查,或使用proper winston exception handling:
import tkinter as tk
def move_label(ndx=[0]):
# the 3 next toggle the column value
rowcol = [(1, 1), (1, 0)]
x, y = rowcol[ndx[0]]
ndx[0] = (ndx[0] + 1) % 2
label_at_1_0.grid(row=x, column=y)
root = tk.Tk()
frame = tk.Frame(root, bg="black")
frame.pack()
label_at_0_0 = tk.Label(frame, text="label_at_0_0")
label_at_0_0.grid(row=0, column=0)
label_at_0_1 = tk.Label(frame, text="not label_at_0_1")
label_at_0_1.grid(row=0, column=1)
label_at_1_0 = tk.Label(frame, text="label_at_1_0")
label_at_1_0.grid(row=1, column=0)
btn_to_move_label = tk.Button(frame, text='move label', command=move_label)
btn_to_move_label.grid(row=1, column=3)
root.mainloop()
但是,在package.json文件中查找与index.js文件相同的目录。在依赖性部分中查找节点池,并将其版本更改为“ node-pool”:“ ^ 3.4.2”,因为您描述的问题很可能已在3.1.8版本中解决。