Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add ability to disable HTTP logs

Chocobozzz90db2b3aedb1
diff --git a/config/default.yaml b/config/default.yaml
index f4c8509118..8d60a87d0c 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -240,6 +240,9 @@ log:
log_ping_requests: true
log_tracker_unknown_infohash: true
+ # If you have many concurrent requests, you can disable HTTP requests logging to reduce PeerTube CPU load
+ log_http_requests: true
+
prettify_sql: false
# Accept warn/error logs coming from the client
diff --git a/config/production.yaml.example b/config/production.yaml.example
index ed03855423..3b2b029ab4 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -238,6 +238,9 @@ log:
log_ping_requests: true
log_tracker_unknown_infohash: true
+ # If you have many concurrent requests, you can disable HTTP requests logging to reduce PeerTube CPU load
+ log_http_requests: true
+
prettify_sql: false
# Accept warn/error logs coming from the client
@@ -470,7 +473,6 @@ user:
video_quota_daily: -1
default_channel_name: 'Main $1 channel' # The placeholder $1 is used to represent the user's username
-
video_channels:
max_per_user: 20 # Allows each user to create up to 20 video channels.
diff --git a/packages/tests/src/api/server/logs.ts b/packages/tests/src/api/server/logs.ts
index 11c86d6942..29cd5ea380 100644
--- a/packages/tests/src/api/server/logs.ts
+++ b/packages/tests/src/api/server/logs.ts
@@ -113,7 +113,7 @@ describe('Test logs', function () {
}
})
- it('Should log ping requests', async function () {
+ it('Should log ping/HTTP requests', async function () {
const now = new Date()
await server.servers.ping()
@@ -122,23 +122,26 @@ describe('Test logs', function () {
const logsString = JSON.stringify(body)
expect(logsString.includes('/api/v1/ping')).to.be.true
+ expect(logsString.includes(' HTTP/1.1')).to.be.true
})
- it('Should not log ping requests', async function () {
+ it('Should not log ping/HTTP requests', async function () {
this.timeout(60000)
await killallServers([ server ])
- await server.run({ log: { log_ping_requests: false } })
+ await server.run({ log: { log_ping_requests: false, log_http_requests: false } })
const now = new Date()
await server.servers.ping()
+ await server.videos.list()
const body = await logsCommand.getLogs({ startDate: now, level: 'info' })
const logsString = JSON.stringify(body)
expect(logsString.includes('/api/v1/ping')).to.be.false
+ expect(logsString.includes(' HTTP/1.1"')).to.be.false
})
})
diff --git a/server/core/initializers/config.ts b/server/core/initializers/config.ts
index 7d0c990a31..a96c7eba95 100644
--- a/server/core/initializers/config.ts
+++ b/server/core/initializers/config.ts
@@ -220,6 +220,7 @@ const CONFIG = {
ANONYMIZE_IP: config.get<boolean>('log.anonymize_ip'),
LOG_PING_REQUESTS: config.get<boolean>('log.log_ping_requests'),
LOG_TRACKER_UNKNOWN_INFOHASH: config.get<boolean>('log.log_tracker_unknown_infohash'),
+ LOG_HTTP_REQUESTS: config.get<boolean>('log.log_http_requests'),
PRETTIFY_SQL: config.get<boolean>('log.prettify_sql'),
ACCEPT_CLIENT_LOG: config.get<boolean>('log.accept_client_log')
},
diff --git a/server/server.ts b/server/server.ts
index 3dc81f22e9..6435212819 100644
--- a/server/server.ts
+++ b/server/server.ts
@@ -167,27 +167,31 @@ if (isTestOrDevInstance()) {
}))
}
-// For the logger
-token('remote-addr', (req: express.Request) => {
- if (CONFIG.LOG.ANONYMIZE_IP === true || req.get('DNT') === '1') {
- return anonymize(req.ip, 16, 16)
- }
+// HTTP logging
+if (CONFIG.LOG.LOG_HTTP_REQUESTS) {
+ token('remote-addr', (req: express.Request) => {
+ if (CONFIG.LOG.ANONYMIZE_IP === true || req.get('DNT') === '1') {
+ return anonymize(req.ip, 16, 16)
+ }
- return req.ip
-})
-token('user-agent', (req: express.Request) => {
- if (req.get('DNT') === '1') {
- return parse(req.get('user-agent')).family
- }
+ return req.ip
+ })
- return req.get('user-agent')
-})
-app.use(morgan('combined', {
- stream: {
- write: (str: string) => logger.info(str.trim(), { tags: [ 'http' ] })
- },
- skip: req => CONFIG.LOG.LOG_PING_REQUESTS === false && req.originalUrl === '/api/v1/ping'
-}))
+ token('user-agent', (req: express.Request) => {
+ if (req.get('DNT') === '1') {
+ return parse(req.get('user-agent')).family
+ }
+
+ return req.get('user-agent')
+ })
+
+ app.use(morgan('combined', {
+ stream: {
+ write: (str: string) => logger.info(str.trim(), { tags: [ 'http' ] })
+ },
+ skip: req => CONFIG.LOG.LOG_PING_REQUESTS === false && req.originalUrl === '/api/v1/ping'
+ }))
+}
// Add .fail() helper to response
app.use(apiFailMiddleware)