@@ -10,23 +10,14 @@ import {
1010import { DocumentBuilder , SwaggerModule } from '@nestjs/swagger' ;
1111import * as config from 'config' ;
1212import { ClsMiddleware } from 'nestjs-cls' ;
13- import { S3StreamLogger , S3StreamLoggerOptions } from 's3-streamlogger' ;
1413import { install } from 'source-map-support' ;
1514import { SPLAT } from 'triple-beam' ;
1615import * as winston from 'winston' ;
1716import { createLogger } from 'winston' ;
1817import { generateModuleGraph } from './commands/graph' ;
1918import { MainModule } from './main.module' ;
20- import { S3ClientConfig } from '@aws-sdk/client-s3' ;
21-
22- // S3StreamLogger passes its config to S3Client, but doesn't accept all the
23- // properties of S3ClientConfig. This allows those properties.
24- interface SafeS3StreamLoggerOptions extends S3StreamLoggerOptions {
25- config : S3StreamLoggerOptions [ 'config' ] & {
26- forcePathStyle : boolean ;
27- endpoint : string ;
28- } ;
29- }
19+ import { S3Client } from '@aws-sdk/client-s3' ;
20+ import { RotatingS3Writable } from './s3-logger/s3-logger' ;
3021
3122const registerSwagger = ( app : NestFastifyApplication ) => {
3223 const documentBuilderConfig = new DocumentBuilder ( )
@@ -106,23 +97,22 @@ const registerMultiPart = async (app: NestFastifyApplication) => {
10697} ;
10798
10899function setupLogger ( ) {
109- const s3StreamOptions : SafeS3StreamLoggerOptions = {
110- rotate_every : 1000 * 60 * 60 * 24 , //1 Day
111- folder : 'logs' ,
112- bucket : config . get < string > ( 'STORAGE.BUCKET' ) ,
113- name_format : '%Y-%b-%d-console.log' , //https://www.npmjs.com/package/strftime
114- config : {
115- region : 'us-east-1' ,
116- credentials : {
117- accessKeyId : config . get ( 'STORAGE.ACCESS_KEY' ) ,
118- secretAccessKey : config . get ( 'STORAGE.SECRET_KEY' ) ,
119- } ,
120- forcePathStyle : true ,
121- endpoint : config . get ( 'STORAGE.URL' ) ,
100+ const s3Client = new S3Client ( {
101+ region : 'us-east-1' ,
102+ credentials : {
103+ accessKeyId : config . get ( 'STORAGE.ACCESS_KEY' ) ,
104+ secretAccessKey : config . get ( 'STORAGE.SECRET_KEY' ) ,
122105 } ,
123- } ;
106+ forcePathStyle : true ,
107+ endpoint : config . get ( 'STORAGE.URL' ) ,
108+ } ) ;
124109
125- const s3Stream = new S3StreamLogger ( s3StreamOptions ) ;
110+ const s3Stream = new RotatingS3Writable ( {
111+ bucket : config . get < string > ( 'STORAGE.BUCKET' ) ,
112+ folder : 'logs' ,
113+ rotateEvery : 1000 * 60 * 60 * 24 , // 1 day
114+ s3Client,
115+ } ) ;
126116
127117 const timeStampFormat = winston . format . timestamp ( {
128118 format : 'YYYY-MMM-DD HH:mm:ss' ,
@@ -145,20 +135,11 @@ function setupLogger() {
145135 const s3Transport = new winston . transports . Stream ( {
146136 level : config . get ( 'LOG_LEVEL' ) ,
147137 stream : s3Stream ,
148- format : winston . format . combine (
149- winston . format . errors ( { stack : true } ) ,
150- timeStampFormat ,
151- messageFormat ,
152- ) ,
138+ format : winston . format . combine ( winston . format . errors ( { stack : true } ) , timeStampFormat , messageFormat ) ,
153139 } ) ;
154140 const consoleTransport = new winston . transports . Console ( {
155141 level : config . get ( 'LOG_LEVEL' ) ,
156- format : winston . format . combine (
157- winston . format . errors ( { stack : true } ) ,
158- timeStampFormat ,
159- messageFormat ,
160- colorFormat ,
161- ) ,
142+ format : winston . format . combine ( winston . format . errors ( { stack : true } ) , timeStampFormat , messageFormat , colorFormat ) ,
162143 } ) ;
163144
164145 return createLogger ( {
@@ -171,10 +152,7 @@ function setupLogger() {
171152 debug : 5 ,
172153 verbose : 6 ,
173154 } ,
174- transports :
175- config . get ( 'ENV' ) === 'production'
176- ? [ consoleTransport , s3Transport ]
177- : [ consoleTransport ] ,
155+ transports : config . get ( 'ENV' ) === 'production' ? [ consoleTransport , s3Transport ] : [ consoleTransport ] ,
178156 } ) ;
179157}
180158
0 commit comments