aboutsummaryrefslogtreecommitdiff
path: root/src/api/structures
diff options
context:
space:
mode:
authorPitu <[email protected]>2020-12-25 02:54:05 +0900
committerPitu <[email protected]>2020-12-25 02:54:05 +0900
commit3051fbe9480f367be93bdcca45104be7b7d69bd8 (patch)
tree5e4b064282c5b96ff5e86383f2a07eebb3bbe70c /src/api/structures
parentCleanup (diff)
downloadhost.fuwn.me-3051fbe9480f367be93bdcca45104be7b7d69bd8.tar.xz
host.fuwn.me-3051fbe9480f367be93bdcca45104be7b7d69bd8.zip
Feat: add rotating logs when running in production env
Diffstat (limited to 'src/api/structures')
-rw-r--r--src/api/structures/Server.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/api/structures/Server.js b/src/api/structures/Server.js
index 6a4abaa..cf2a781 100644
--- a/src/api/structures/Server.js
+++ b/src/api/structures/Server.js
@@ -7,6 +7,8 @@ const RateLimit = require('express-rate-limit');
const bodyParser = require('body-parser');
const jetpack = require('fs-jetpack');
const path = require('path');
+const morgan = require('morgan');
+const rfs = require('rotating-file-stream');
const log = require('../utils/Log');
// eslint-disable-next-line no-unused-vars
@@ -33,6 +35,14 @@ class Server {
});
this.server.use(bodyParser.urlencoded({ extended: true }));
this.server.use(bodyParser.json());
+
+ if (process.env.NODE_ENV === 'production') {
+ const accessLogStream = rfs.createStream('access.log', {
+ interval: '1d', // rotate daily
+ path: path.join(__dirname, '../../../logs', 'log')
+ });
+ this.server.use(morgan('combined', { stream: accessLogStream }));
+ }
// this.server.use(rateLimiter);
// Serve the uploads