Add ability to disable HTTP logs
This commit is contained in:
parent
edc3ff6085
commit
90db2b3aed
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -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')
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue