Skip to content

Commit

Permalink
Update logging settings
Browse files Browse the repository at this point in the history
- Use winston-daily-rotate-file for logfiles
- Move logs to subdirectory
- Compress old logfiles
  • Loading branch information
HSZemi committed Jun 29, 2022
1 parent 7121bd9 commit 6d1745a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ recentDrafts.json
serverState.json
*.log
*.log.xz
*.log.gz

# See https://help.github.com/ignore-files/ for more about ignoring files.
.idea/
Expand Down
73 changes: 72 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"socket.io": "^4.4.1",
"socket.io-client": "^4.4.1",
"uuid": "^8.3.0",
"winston": "^3.3.3"
"winston": "^3.8.0",
"winston-daily-rotate-file": "^4.7.1"
},
"scripts": {
"start": "export PORT=3001 && react-scripts start",
Expand Down
6 changes: 4 additions & 2 deletions src/util/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import winston from "winston";
import 'winston-daily-rotate-file';

export const logger = (typeof window === 'undefined') ? winston.createLogger({
level: 'info',
Expand All @@ -8,8 +9,9 @@ export const logger = (typeof window === 'undefined') ? winston.createLogger({
winston.format.json(),
),
transports: [
new winston.transports.File({filename: 'error.log', level: 'error'}),
new winston.transports.File({filename: 'aoe2cm.log', maxsize: 10485760}),
new winston.transports.File({filename: 'log/error.log', level: 'error'}),
new winston.transports.DailyRotateFile({filename: 'log/aoe2cm-%DATE%.log',
datePattern: 'YYYY-MM-DD', maxSize: '20m', zippedArchive: true}),
new winston.transports.Console(),
]
}) : {
Expand Down

0 comments on commit 6d1745a

Please sign in to comment.