* Builds a log entry object with common fields * @param {object} req - HTTP request object * @param {object} params - Server access log parameters from req.serverAccessLog * @param {object} options - Variable fields for the log entry * @return {object} Log entry object
(req, params, options)
| 474 | * @return {object} Log entry object |
| 475 | */ |
| 476 | function buildLogEntry(req, params, options) { |
| 477 | const authInfo = params.authInfo; |
| 478 | |
| 479 | return { |
| 480 | // Werelog fields |
| 481 | // logs.access_logs_ingest.timestamp in Clickhouse is of type DateTime so it expects seconds as an integer. |
| 482 | time: Math.floor(Date.now() / 1000), |
| 483 | hostname, |
| 484 | pid: process.pid, |
| 485 | |
| 486 | // Analytics |
| 487 | action: params.analyticsAction ?? undefined, |
| 488 | accountName: params.analyticsAccountName ?? undefined, |
| 489 | userName: params.analyticsUserName ?? undefined, |
| 490 | httpMethod: req.method ?? undefined, |
| 491 | bytesDeleted: options.bytesDeleted ?? undefined, |
| 492 | bytesReceived: options.bytesReceived ?? undefined, |
| 493 | bodyLength: options.bodyLength ?? undefined, |
| 494 | contentLength: options.contentLength ?? undefined, |
| 495 | // eslint-disable-next-line camelcase |
| 496 | elapsed_ms: options.elapsed_ms ?? undefined, |
| 497 | |
| 498 | // AWS access server logs fields https://docs.aws.amazon.com/AmazonS3/latest/userguide/LogFormat.html |
| 499 | startTime: timestampToDateTime643(params.startTimeUnixMS) ?? undefined, // AWS "Time" field |
| 500 | requester: getRequester(authInfo) ?? undefined, |
| 501 | operation: options.operation ?? undefined, |
| 502 | requestURI: options.requestURI ?? undefined, |
| 503 | errorCode: options.errorCode ?? undefined, |
| 504 | objectSize: options.objectSize ?? undefined, |
| 505 | totalTime: options.totalTime ?? undefined, |
| 506 | turnAroundTime: options.turnAroundTime ?? undefined, |
| 507 | referer: options.referer ?? undefined, |
| 508 | userAgent: options.userAgent ?? undefined, |
| 509 | versionId: options.versionId ?? undefined, |
| 510 | signatureVersion: authInfo?.getAuthVersion() ?? undefined, |
| 511 | cipherSuite: req.socket?.encrypted |
| 512 | ? req.socket.getCipher()['standardName'] |
| 513 | : req.headers?.['x-ssl-cipher'] ?? undefined, |
| 514 | authenticationType: authInfo?.getAuthType() ?? undefined, |
| 515 | hostHeader: req.headers?.host ?? undefined, |
| 516 | tlsVersion: req.socket?.encrypted |
| 517 | ? req.socket.getCipher()['version'] |
| 518 | : req.headers?.['x-ssl-protocol'] ?? undefined, |
| 519 | aclRequired: options.aclRequired ?? undefined, |
| 520 | // hostID: undefined, // NOT IMPLEMENTED |
| 521 | // accessPointARN: undefined, // NOT IMPLEMENTED |
| 522 | |
| 523 | // Shared between AWS access server logs and Analytics logs |
| 524 | bucketOwner: params.bucketOwner ?? undefined, |
| 525 | bucketName: params.bucketName ?? undefined, // AWS "Bucket" field |
| 526 | // eslint-disable-next-line camelcase |
| 527 | req_id: options.requestID ?? undefined, // AWS "Request ID" field |
| 528 | bytesSent: options.bytesSent ?? undefined, |
| 529 | clientIP: getRemoteIPFromRequest(req) ?? undefined, // AWS 'Remote IP' field |
| 530 | httpCode: options.httpCode ?? undefined, // AWS "HTTP Status" field |
| 531 | objectKey: options.objectKey ?? undefined, // AWS "Key" field |
| 532 | |
| 533 | // Scality server access logs extra fields |
no test coverage detected