Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixing logger for custom S3 stream #3900

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions packages/server/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { hostname } from 'node:os'
import config from './config' // should be replaced by node-config or similar
import { createLogger, transports, format } from 'winston'
import { NextFunction, Request, Response } from 'express'
import { S3ClientConfig } from '@aws-sdk/client-s3'

const { S3StreamLogger } = require('s3-streamlogger')

Expand All @@ -17,32 +18,38 @@ if (process.env.STORAGE_TYPE === 's3') {
const secretAccessKey = process.env.S3_STORAGE_SECRET_ACCESS_KEY
const region = process.env.S3_STORAGE_REGION
const s3Bucket = process.env.S3_STORAGE_BUCKET_NAME
const customURL = process.env.S3_ENDPOINT_URL
const forcePathStyle = process.env.S3_FORCE_PATH_STYLE === 'true'

const s3Config: S3ClientConfig = {
region: region,
endpoint: customURL,
forcePathStyle: forcePathStyle,
credentials: {
accessKeyId: accessKeyId as string,
secretAccessKey: secretAccessKey as string
}
}

s3ServerStream = new S3StreamLogger({
bucket: s3Bucket,
folder: 'logs/server',
region,
access_key_id: accessKeyId,
secret_access_key: secretAccessKey,
name_format: `server-%Y-%m-%d-%H-%M-%S-%L-${hostname()}.log`
name_format: `server-%Y-%m-%d-%H-%M-%S-%L-${hostname()}.log`,
config: s3Config
})

s3ErrorStream = new S3StreamLogger({
bucket: s3Bucket,
folder: 'logs/error',
region,
access_key_id: accessKeyId,
secret_access_key: secretAccessKey,
name_format: `server-error-%Y-%m-%d-%H-%M-%S-%L-${hostname()}.log`
name_format: `server-error-%Y-%m-%d-%H-%M-%S-%L-${hostname()}.log`,
config: s3Config
})

s3ServerReqStream = new S3StreamLogger({
bucket: s3Bucket,
folder: 'logs/requests',
region,
access_key_id: accessKeyId,
secret_access_key: secretAccessKey,
name_format: `server-requests-%Y-%m-%d-%H-%M-%S-%L-${hostname()}.log.jsonl`
name_format: `server-requests-%Y-%m-%d-%H-%M-%S-%L-${hostname()}.log.jsonl`,
config: s3Config
})
}

Expand Down
Loading