Skip to content

Commit

Permalink
fix(logs): rotate logs on a daily basis instead of incrementing log f…
Browse files Browse the repository at this point in the history
…ilename
  • Loading branch information
sct committed Dec 24, 2020
1 parent bd94740 commit 395cbb2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ config/settings.json

# logs
config/logs/*.log*
config/logs/*.json

# dist files
dist
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"typeorm": "^0.2.29",
"uuid": "^8.3.2",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.0",
"xml2js": "^0.4.23",
"yamljs": "^0.3.0",
"yup": "^0.32.8"
Expand Down
24 changes: 20 additions & 4 deletions server/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import * as winston from 'winston';
import 'winston-daily-rotate-file';
import path from 'path';
import fs from 'fs';

// Migrate away from old log
const OLD_LOG_FILE = path.join(__dirname, '../config/logs/overseerr.log');
if (fs.existsSync(OLD_LOG_FILE)) {
const file = fs.lstatSync(OLD_LOG_FILE);

if (!file.isSymbolicLink()) {
fs.unlinkSync(OLD_LOG_FILE);
}
}

const hformat = winston.format.printf(
({ level, label, message, timestamp, ...metadata }) => {
Expand Down Expand Up @@ -29,10 +41,14 @@ const logger = winston.createLogger({
hformat
),
}),
new winston.transports.File({
filename: path.join(__dirname, '../config/logs/overseerr.log'),
maxsize: 20971520,
maxFiles: 6,
new winston.transports.DailyRotateFile({
filename: path.join(__dirname, '../config/logs/overseerr-%DATE%.log'),
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '7d',
createSymlink: true,
symlinkName: 'overseerr.log',
}),
],
});
Expand Down
23 changes: 20 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6114,6 +6114,13 @@ file-entry-cache@^6.0.0:
dependencies:
flat-cache "^3.0.4"

file-stream-rotator@^0.5.7:
version "0.5.7"
resolved "https://registry.yarnpkg.com/file-stream-rotator/-/file-stream-rotator-0.5.7.tgz#868a2e5966f7640a17dd86eda0e4467c089f6286"
integrity sha512-VYb3HZ/GiAGUCrfeakO8Mp54YGswNUHvL7P09WQcXAJNSj3iQ5QraYSp3cIn1MUyw6uzfgN/EFOarCNa4JvUHQ==
dependencies:
moment "^2.11.2"

file-uri-to-path@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
Expand Down Expand Up @@ -9050,7 +9057,7 @@ moment-timezone@^0.5.31:
dependencies:
moment ">= 2.9.0"

"moment@>= 2.9.0":
"moment@>= 2.9.0", moment@^2.11.2:
version "2.29.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
Expand Down Expand Up @@ -9828,7 +9835,7 @@ object-copy@^0.1.0:
define-property "^0.2.5"
kind-of "^3.0.3"

object-hash@^2.0.3:
object-hash@^2.0.1, object-hash@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-2.0.3.tgz#d12db044e03cd2ca3d77c0570d87225b02e1e6ea"
integrity sha512-JPKn0GMu+Fa3zt3Bmr66JhokJU5BaNBIh4ZeTlaCBzrBsOeXzwcKKAK1tbLiPKgvwmPXsDvvLHoWh5Bm7ofIYg==
Expand Down Expand Up @@ -14157,7 +14164,17 @@ widest-line@^3.1.0:
dependencies:
string-width "^4.0.0"

winston-transport@^4.4.0:
winston-daily-rotate-file@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/winston-daily-rotate-file/-/winston-daily-rotate-file-4.5.0.tgz#3914ac57c4bdae1138170bec85af0c2217b253b1"
integrity sha512-/HqeWiU48dzGqcrABRlxYWVMdL6l3uKCtFSJyrqK+E2rLnSFNsgYpvwx15EgTitBLNzH69lQd/+z2ASryV2aqw==
dependencies:
file-stream-rotator "^0.5.7"
object-hash "^2.0.1"
triple-beam "^1.3.0"
winston-transport "^4.2.0"

winston-transport@^4.2.0, winston-transport@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/winston-transport/-/winston-transport-4.4.0.tgz#17af518daa690d5b2ecccaa7acf7b20ca7925e59"
integrity sha512-Lc7/p3GtqtqPBYYtS6KCN3c77/2QCev51DvcJKbkFPQNoj1sinkGwLGFDxkXY9J6p9+EPnYs+D90uwbnaiURTw==
Expand Down

0 comments on commit 395cbb2

Please sign in to comment.