Add rotating log files #280
3 changed files with 45 additions and 6 deletions
|
@ -45,6 +45,7 @@
|
||||||
"ts-jest": "^29.0.0",
|
"ts-jest": "^29.0.0",
|
||||||
"typeorm": "0.3.20",
|
"typeorm": "0.3.20",
|
||||||
"winston": "^3.11.0",
|
"winston": "^3.11.0",
|
||||||
|
"winston-daily-rotate-file": "^5.0.0",
|
||||||
"winston-discord-transport": "^1.3.0"
|
"winston-discord-transport": "^1.3.0"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
import path from "path";
|
||||||
import { Logger, createLogger, format, transports } from "winston";
|
import { Logger, createLogger, format, transports } from "winston";
|
||||||
|
import DailyRotateFile from "winston-daily-rotate-file";
|
||||||
import DiscordTransport from "winston-discord-transport";
|
import DiscordTransport from "winston-discord-transport";
|
||||||
|
|
||||||
export default class AppLogger {
|
export default class AppLogger {
|
||||||
|
@ -20,12 +22,21 @@ export default class AppLogger {
|
||||||
customFormat,
|
customFormat,
|
||||||
),
|
),
|
||||||
defaultMeta: { service: "bot" },
|
defaultMeta: { service: "bot" },
|
||||||
transports: [
|
transports: [],
|
||||||
new transports.File({ filename: "priority.log", level: "warn" }),
|
|
||||||
new transports.File({ filename: "combined.log" }),
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (process.env.DATA_DIR) {
|
||||||
|
const logDir = path.join(process.env.DATA_DIR, "logs");
|
||||||
|
|
||||||
|
logger.add(new DailyRotateFile({
|
||||||
|
filename: "bot-%DATE%.log",
|
||||||
|
dirname: logDir,
|
||||||
|
datePattern: "YYYY-MM-DD-HH",
|
||||||
|
maxSize: "20m",
|
||||||
|
maxFiles: "14d",
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
if (outputToConsole) {
|
if (outputToConsole) {
|
||||||
logger.add(new transports.Console({
|
logger.add(new transports.Console({
|
||||||
format: format.combine(
|
format: format.combine(
|
||||||
|
|
29
yarn.lock
29
yarn.lock
|
@ -2680,6 +2680,13 @@ file-entry-cache@^6.0.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
flat-cache "^3.0.4"
|
flat-cache "^3.0.4"
|
||||||
|
|
||||||
|
file-stream-rotator@^0.6.1:
|
||||||
|
version "0.6.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/file-stream-rotator/-/file-stream-rotator-0.6.1.tgz#007019e735b262bb6c6f0197e58e5c87cb96cec3"
|
||||||
|
integrity sha512-u+dBid4PvZw17PmDeRcNOtCP9CCK/9lRN2w+r1xIS7yOL9JFrIBKTvrYsxT4P0pGtThYTn++QS5ChHaUov3+zQ==
|
||||||
|
dependencies:
|
||||||
|
moment "^2.29.1"
|
||||||
|
|
||||||
fill-range@^7.1.1:
|
fill-range@^7.1.1:
|
||||||
version "7.1.1"
|
version "7.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292"
|
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292"
|
||||||
|
@ -4416,6 +4423,11 @@ mkdirp@^2.1.3:
|
||||||
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-2.1.6.tgz#964fbcb12b2d8c5d6fbc62a963ac95a273e2cc19"
|
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-2.1.6.tgz#964fbcb12b2d8c5d6fbc62a963ac95a273e2cc19"
|
||||||
integrity sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==
|
integrity sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==
|
||||||
|
|
||||||
|
moment@^2.29.1:
|
||||||
|
version "2.30.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
|
||||||
|
integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==
|
||||||
|
|
||||||
ms@2.0.0:
|
ms@2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
||||||
|
@ -4630,6 +4642,11 @@ object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
|
||||||
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
|
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
|
||||||
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==
|
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==
|
||||||
|
|
||||||
|
object-hash@^3.0.0:
|
||||||
|
version "3.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-3.0.0.tgz#73f97f753e7baffc0e2cc9d6e079079744ac82e9"
|
||||||
|
integrity sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==
|
||||||
|
|
||||||
object-inspect@^1.13.1:
|
object-inspect@^1.13.1:
|
||||||
version "1.13.1"
|
version "1.13.1"
|
||||||
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.1.tgz#b96c6109324ccfef6b12216a956ca4dc2ff94bc2"
|
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.1.tgz#b96c6109324ccfef6b12216a956ca4dc2ff94bc2"
|
||||||
|
@ -5856,7 +5873,7 @@ tr46@~0.0.3:
|
||||||
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
|
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
|
||||||
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
|
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
|
||||||
|
|
||||||
triple-beam@^1.2.0, triple-beam@^1.3.0:
|
triple-beam@^1.2.0, triple-beam@^1.3.0, triple-beam@^1.4.1:
|
||||||
version "1.4.1"
|
version "1.4.1"
|
||||||
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.4.1.tgz#6fde70271dc6e5d73ca0c3b24e2d92afb7441984"
|
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.4.1.tgz#6fde70271dc6e5d73ca0c3b24e2d92afb7441984"
|
||||||
integrity sha512-aZbgViZrg1QNcG+LULa7nhZpJTZSLm/mXnHXnbAbjmN5aSa0y7V+wvv6+4WaBtpISJzThKy+PIPxc1Nq1EJ9mg==
|
integrity sha512-aZbgViZrg1QNcG+LULa7nhZpJTZSLm/mXnHXnbAbjmN5aSa0y7V+wvv6+4WaBtpISJzThKy+PIPxc1Nq1EJ9mg==
|
||||||
|
@ -6165,6 +6182,16 @@ widest-line@^4.0.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
string-width "^5.0.1"
|
string-width "^5.0.1"
|
||||||
|
|
||||||
|
winston-daily-rotate-file@^5.0.0:
|
||||||
|
version "5.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/winston-daily-rotate-file/-/winston-daily-rotate-file-5.0.0.tgz#8cd94800025490e47c00ec892b655a5821f4266d"
|
||||||
|
integrity sha512-JDjiXXkM5qvwY06733vf09I2wnMXpZEhxEVOSPenZMii+g7pcDcTBt2MRugnoi8BwVSuCT2jfRXBUy+n1Zz/Yw==
|
||||||
|
dependencies:
|
||||||
|
file-stream-rotator "^0.6.1"
|
||||||
|
object-hash "^3.0.0"
|
||||||
|
triple-beam "^1.4.1"
|
||||||
|
winston-transport "^4.7.0"
|
||||||
|
|
||||||
winston-discord-transport@^1.3.0:
|
winston-discord-transport@^1.3.0:
|
||||||
version "1.3.0"
|
version "1.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/winston-discord-transport/-/winston-discord-transport-1.3.0.tgz#5fcef49a1a4838183921a44d6df029af55a5c8d0"
|
resolved "https://registry.yarnpkg.com/winston-discord-transport/-/winston-discord-transport-1.3.0.tgz#5fcef49a1a4838183921a44d6df029af55a5c8d0"
|
||||||
|
|
Loading…
Reference in a new issue