浏览代码

feat: allow administrator to disable logging of ping requests

Johan Fleury 3 年之前
父节点
当前提交
12c1e38df2

+ 1 - 0
config/default.yaml

@@ -100,6 +100,7 @@ log:
     maxFileSize: 12MB
     maxFiles: 20
   anonymizeIP: false
+  log_ping_requests: true
 
 trending:
   videos:

+ 1 - 0
config/production.yaml.example

@@ -100,6 +100,7 @@ log:
     maxFileSize: 12MB
     maxFiles: 20
   anonymizeIP: false
+  log_ping_requests: true
 
 trending:
   videos:

+ 4 - 1
server.ts

@@ -158,7 +158,10 @@ morgan.token('user-agent', (req: express.Request) => {
   return req.get('user-agent')
 })
 app.use(morgan('combined', {
-  stream: { write: logger.info.bind(logger) }
+  stream: { write: logger.info.bind(logger) },
+  skip: function (req, res) {
+    return (req.path === '/api/v1/ping' && CONFIG.LOG.LOG_PING_REQUESTS === false)
+  },
 }))
 
 // For body requests

+ 2 - 1
server/initializers/config.ts

@@ -104,7 +104,8 @@ const CONFIG = {
       MAX_FILE_SIZE: bytes.parse(config.get<string>('log.rotation.maxFileSize')),
       MAX_FILES: config.get<number>('log.rotation.maxFiles')
     },
-    ANONYMIZE_IP: config.get<boolean>('log.anonymizeIP')
+    ANONYMIZE_IP: config.get<boolean>('log.anonymizeIP'),
+    LOG_PING_REQUESTS: config.get<boolean>('log.log_ping_requests')
   },
   TRENDING: {
     VIDEOS: {

+ 5 - 0
support/docker/production/config/custom-environment-variables.yaml

@@ -42,6 +42,11 @@ smtp:
     __format: "json"
   from_address: "PEERTUBE_SMTP_FROM"
 
+log:
+  log_ping_requests:
+    __name: "PEERTUBE_LOG_PING_REQUESTS"
+    __format: "json"
+
 user:
   video_quota:
     __name: "PEERTUBE_USER_VIDEO_QUOTA"