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

feat: resolve circular json serialization issue #382

Merged
merged 5 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions apps/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"bullmq": "^5.25.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"flatted": "^3.3.2",
"graphql": "^16.9.0",
"graphql-type-json": "^0.3.2",
"mailgun.js": "^10.2.3",
Expand Down
7 changes: 4 additions & 3 deletions apps/api/src/common/logger/slogerr.transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TransportStreamOptions } from 'winston-transport';
import { ConfigService } from '@nestjs/config';
import { Logger } from '@nestjs/common/services/logger.service';
import { firstValueFrom } from 'rxjs';
import { stringify } from 'flatted';

interface CustomTransportOptions extends TransportStreamOptions {
httpService: HttpService;
Expand Down Expand Up @@ -40,7 +41,7 @@ export class SlogerrTransport extends TransportStream {
const apiEndpoint = this.configService.get<string>('SLOGERR_API_ENDPOINT');
const apiKey = this.configService.get<string>('SLOGERR_API_TOKEN');

this.logger.log(`Log Info: ${JSON.stringify(info)}`);
this.logger.log(`Log Info: ${stringify(info)}`);

const logCreatedOn = info.timestamp || new Date().toISOString();

Expand All @@ -65,14 +66,14 @@ export class SlogerrTransport extends TransportStream {
);

if (response.status !== 200) {
this.logger.error(
this.logger.warn(
`Failed to send log to Slogerr. Status: ${response.status}, Message: ${response.statusText}`,
);
} else {
this.logger.log('Error log successfully sent to Slogerr', response);
}
} catch (error) {
this.logger.error('Failed to send log to Slogerr', error.message);
this.logger.warn('Failed to send log to Slogerr', error.message);
}
}

Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/config/logger.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ConfigService } from '@nestjs/config';
import { name as applicationName } from 'package.json';
import DailyRotateFile from 'winston-daily-rotate-file';
import { SlogerrTransport } from 'src/common/logger/slogerr.transport';
import { stringify } from 'flatted';

const configService = new ConfigService();
const httpService = new HttpService();
Expand Down Expand Up @@ -39,7 +40,7 @@ const logFormat = format.combine(
message,
stackTrace: stack,
};
return JSON.stringify(logObject);
return stringify(logObject);
}),
);

Expand Down
Loading