Skip to content

Commit

Permalink
fix: Fixing logger for custom S3 stream (FlowiseAI#3900)
Browse files Browse the repository at this point in the history
* fix: Fixing logger for custom S3 stream

* fix: adjusting s3 stream folder

* fix: fixing forcedPathStyle variable name.

* Update logger.ts

* add S3ClientConfig types

---------

Co-authored-by: Henry Heng <henryheng@flowiseai.com>
  • Loading branch information
2 people authored and JJK801 committed Feb 3, 2025
1 parent 55a2f83 commit aded1b3
Showing 1 changed file with 19 additions and 12 deletions.
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

0 comments on commit aded1b3

Please sign in to comment.