Skip to content

Commit 7ca637a

Browse files
Add log rotation settings
1 parent 7aef02d commit 7ca637a

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

backend/.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ MONGODB_URI=mongodb://localhost:27017/github-value
1919
# Webhook proxy URL (optional)
2020
# This is only needed if you don't want to use smee.io
2121
# WEBHOOK_PROXY_URL=https://5950-2601-589-4885-e850-b1eb-a754-b856-6038.ngrok-free.app
22+
#
23+
24+
# Log rotation settings
25+
# In observing organizations with large amounts of activity, the debug logs can
26+
# grow quite large, so having flexibility about how long to store those helps.
27+
# LOG_ROTATION_PERIOD=1d
28+
# LOG_ROTATION_COUNT=14

backend/src/services/logger.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import bunyan from 'bunyan';
22
import { existsSync, mkdirSync, readFileSync } from 'fs';
33
import { Request, Response, NextFunction } from 'express';
44
import path, { dirname } from 'path';
5+
import process from 'node:process';
56
import { fileURLToPath } from 'url';
67

78
const __filename = fileURLToPath(import.meta.url);
@@ -16,6 +17,9 @@ const packageJsonPath = path.resolve(__dirname, '../../package.json');
1617
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
1718
export const appName = packageJson.name || 'GitHub Value';
1819

20+
const period = process.env.LOG_ROTATION_PERIOD || '1d';
21+
const count = parseInt(process.env.LOG_ROTATION_COUNT ?? '14');
22+
1923
const logger = bunyan.createLogger({
2024
name: appName,
2125
level: 'debug',
@@ -42,14 +46,16 @@ const logger = bunyan.createLogger({
4246
},
4347
{
4448
path: `${logsDir}/error.json`,
45-
period: '1d',
46-
count: 14,
49+
type: 'rotating-file',
50+
period: period,
51+
count: count,
4752
level: 'error'
4853
},
4954
{
5055
path: `${logsDir}/debug.json`,
51-
period: '1d',
52-
count: 14,
56+
type: 'rotating-file',
57+
period: period,
58+
count: count,
5359
level: 'debug'
5460
}
5561
]

0 commit comments

Comments
 (0)