我编写了如下代码来记录快速日志。
const rfs = require("rotating-file-stream");
function formatDate() {
var d = new Date(),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
hour = d.getHours();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
if (hour.length < 2)
hour = '0' + hour
return [year, month, day, hour].join('-');
}
let log_directory = '/../logs/';
let log_date = formatDate()
let log_file_name = path.normalize(__dirname + log_directory + log_date, 'access.log');
let accessLogStream = rfs.createStream(log_file_name, {
size: "300M",
interval: "1d",
})
app.use(morgan(':date[iso] :method :url :body :headers :remote-addr :req[content-length] - :status :response-time ms - :res[content-length] ', { stream: accessLogStream }));
日志按预期存储在项目之外。
但是在轮换之后,日志以以下文件夹名称存储在项目中
20200507-0943-01-
20200508-0943-01-
20200509-0943-01-
20200510-0943-01-
20200511-0943-01-
20200512-0943-01-
20200513-0944-01-
package.json
package-lock.json
public
routes
scripts
services
app.js
我不希望在项目中创建这些文件夹。有没有办法处理这个?