aboutsummaryrefslogtreecommitdiff
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
parentCleanup (diff)
downloadhost.fuwn.me-3051fbe9480f367be93bdcca45104be7b7d69bd8.tar.xz
host.fuwn.me-3051fbe9480f367be93bdcca45104be7b7d69bd8.zip
Feat: add rotating logs when running in production env
-rw-r--r--.gitignore2
-rw-r--r--package.json3
-rw-r--r--src/api/structures/Server.js10
-rw-r--r--yarn.lock47
4 files changed, 59 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index e52633d..0b41d46 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,7 @@
node_modules/
dist/
.nuxt/
-
+logs/
# Lolisafe specifics
database.sqlite
uploads/
diff --git a/package.json b/package.json
index e8a91f1..d5e8d37 100644
--- a/package.json
+++ b/package.json
@@ -46,6 +46,7 @@
"dumper.js": "^1.3.1",
"express": "^4.17.1",
"express-rate-limit": "^3.4.0",
+ "ffmpeg-probe": "^1.0.6",
"file-saver": "^2.0.1",
"fluent-ffmpeg": "^2.1.2",
"fs-jetpack": "^2.2.2",
@@ -55,6 +56,7 @@
"knex": "^0.16.3",
"masonry-layout": "^4.2.2",
"moment": "^2.24.0",
+ "morgan": "^1.10.0",
"multer": "^1.4.1",
"mysql": "^2.16.0",
"nuxt": "2.12.2",
@@ -62,6 +64,7 @@
"pg": "^7.8.1",
"qoa": "^0.2.0",
"randomstring": "^1.1.5",
+ "rotating-file-stream": "^2.1.3",
"search-query-parser": "^1.5.5",
"serve-static": "^1.13.2",
"sharp": "^0.25.2",
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
diff --git a/yarn.lock b/yarn.lock
index 8606548..4196ea0 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1749,6 +1749,13 @@ base@^0.11.1:
mixin-deep "^1.2.0"
pascalcase "^0.1.1"
+basic-auth@~2.0.1:
+ version "2.0.1"
+ resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a"
+ integrity sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==
+ dependencies:
+ safe-buffer "5.1.2"
+
bcrypt-pbkdf@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e"
@@ -2770,7 +2777,7 @@ cross-spawn@^5.0.1:
shebang-command "^1.2.0"
which "^1.2.9"
-cross-spawn@^6.0.5:
+cross-spawn@^6.0.0, cross-spawn@^6.0.5:
version "6.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==
@@ -3171,7 +3178,7 @@ delegates@^1.0.0:
resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a"
integrity sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=
[email protected], depd@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df"
integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==
@@ -3690,6 +3697,19 @@ evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3:
md5.js "^1.3.4"
safe-buffer "^5.1.1"
+execa@^0.10.0:
+ version "0.10.0"
+ resolved "https://registry.yarnpkg.com/execa/-/execa-0.10.0.tgz#ff456a8f53f90f8eccc71a96d11bdfc7f082cb50"
+ integrity sha512-7XOMnz8Ynx1gGo/3hyV9loYNPWM94jG3+3T3Y8tsfSstFmETmENCMU/A/zj8Lyaj1lkgEepKepvd6240tBRvlw==
+ dependencies:
+ cross-spawn "^6.0.0"
+ get-stream "^3.0.0"
+ is-stream "^1.1.0"
+ npm-run-path "^2.0.0"
+ p-finally "^1.0.0"
+ signal-exit "^3.0.0"
+ strip-eof "^1.0.0"
+
execa@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-0.7.0.tgz#944becd34cc41ee32a63a9faf27ad5a65fc59777"
@@ -3881,6 +3901,13 @@ [email protected]:
resolved "https://registry.yarnpkg.com/feature-policy/-/feature-policy-0.3.0.tgz#7430e8e54a40da01156ca30aaec1a381ce536069"
integrity sha512-ZtijOTFN7TzCujt1fnNhfWPFPSHeZkesff9AXZj+UEjYBynWNUIYpC87Ve4wHzyexQsImicLu7WsC2LHq7/xrQ==
+ffmpeg-probe@^1.0.6:
+ version "1.0.6"
+ resolved "https://registry.yarnpkg.com/ffmpeg-probe/-/ffmpeg-probe-1.0.6.tgz#4dbb127665ef290fb1b3b51cbecca2d8c7c72406"
+ integrity sha512-zxH4MYEtrbafVQ5p1doGzHjUmjt3zI4cdKFSNVbBMKy0bTc/KwqYwnGsnQVlyBcXgqBPw2YwGBEWF53MRLh3Sw==
+ dependencies:
+ execa "^0.10.0"
+
figgy-pudding@^3.5.1:
version "3.5.2"
resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.2.tgz#b4eee8148abb01dcf1d1ac34367d59e12fa61d6e"
@@ -6069,6 +6096,17 @@ moment@^2.24.0:
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==
+morgan@^1.10.0:
+ version "1.10.0"
+ resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.10.0.tgz#091778abc1fc47cd3509824653dae1faab6b17d7"
+ integrity sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==
+ dependencies:
+ basic-auth "~2.0.1"
+ debug "2.6.9"
+ depd "~2.0.0"
+ on-finished "~2.3.0"
+ on-headers "~1.0.2"
+
move-concurrently@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
@@ -8373,6 +8411,11 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
hash-base "^3.0.0"
inherits "^2.0.1"
+rotating-file-stream@^2.1.3:
+ version "2.1.3"
+ resolved "https://registry.yarnpkg.com/rotating-file-stream/-/rotating-file-stream-2.1.3.tgz#4b3cc8f56ae70b3e30ccdb4ee6b14d95e66b02bb"
+ integrity sha512-zZ4Tkngxispo7DgiTqX0s4ChLtM3qET6iYsDA9tmgDEqJ3BFgRq/ZotsKEDAYQt9pAn9JwwqT27CSwQt3CTxNg==
+
run-async@^2.2.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.0.tgz#e59054a5b86876cfae07f431d18cbaddc594f1e8"