Skip to content

Commit

Permalink
feat: upgrade logger, move to peer dep (PL-000) (#114)
Browse files Browse the repository at this point in the history
Migration path:
- Upgrade to `@voiceflow/[email protected]`, with new instantiation.
- Remove exception middleware from express
- Ensure `createHTTPLogger` is added to express

BREAKING CHANGE: Move to `@voiceflow/logger` v2, as a peer dep.

BREAKING CHANGE: Remove the exception middleware, as this same functionality is done better by the `pino-http` logger in `@voiceflow/logger`.

Co-authored-by: Tyler Stewart <[email protected]>
  • Loading branch information
trs and trs committed Feb 5, 2024
1 parent 81967c5 commit 3b4cdb5
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 459 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
},
"dependencies": {
"@types/http-errors": "^1.8.2",
"@voiceflow/logger": "1.6.1",
"@voiceflow/verror": "1.1.3",
"chai": "^4.3.4",
"dotenv": "^10.0.0",
Expand Down Expand Up @@ -45,6 +44,7 @@
"@voiceflow/common": "7.27.3",
"@voiceflow/eslint-config": "6.1.0",
"@voiceflow/git-branch-check": "1.4.0",
"@voiceflow/logger": "2.2.0",
"@voiceflow/prettier-config": "1.2.1",
"@voiceflow/tsconfig": "1.4.3",
"chai-as-promised": "^7.1.1",
Expand Down Expand Up @@ -81,6 +81,7 @@
"@types/express": "^4.17.13",
"@types/ioredis": "^4.28.10",
"@voiceflow/common": "^7.2.0",
"@voiceflow/logger": "^2",
"express-validator": "^6.3.0",
"ioredis": "^4.28.5",
"jszip": "^3.7.1"
Expand Down
9 changes: 5 additions & 4 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Logger from '@voiceflow/logger';
import { createLogger, LogFormat, LogLevel } from '@voiceflow/logger';

const options = ['local', 'test'].includes(process.env.NODE_ENV!) ? { level: 'info' as any, pretty: true } : {};

const log = new Logger(options);
const log = createLogger({
format: LogFormat.INLINE,
level: (process.env.LOG_LEVEL as LogLevel) ?? LogLevel.INFO,
});

export default log;
15 changes: 0 additions & 15 deletions src/middlewares/exception/formatters/gaxiosError.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/middlewares/exception/formatters/httpError.ts

This file was deleted.

28 changes: 0 additions & 28 deletions src/middlewares/exception/formatters/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/middlewares/exception/formatters/jsError.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/middlewares/exception/formatters/vError.ts

This file was deleted.

32 changes: 0 additions & 32 deletions src/middlewares/exception/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/middlewares/exception/types.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/middlewares/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './exception';
export * from './rateLimit';
8 changes: 3 additions & 5 deletions src/responseBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@ class ResponseBuilder {
* @param codeOverride optionally override the code specified in the error
* @param req request object
*/
// eslint-disable-next-line sonarjs/cognitive-complexity
private static errorResponse<T>(
error: (Error & { data?: T }) | string,
codeOverride?: HttpStatus,
req?: Request & { user?: { id: number } }
): ErrorResponse<T> {
if (error && (error as any).isAxiosError) {
log.error(`@backend-utils:errorResponse - error:axios:${JSON.stringify(ResponseBuilder.getAxiosError(error as AxiosError))}`);
log.error(`@backend-utils:errorResponse - error:axios %o`, ResponseBuilder.getAxiosError(error as AxiosError));
}

if (!(error instanceof Error)) {
Expand Down Expand Up @@ -128,9 +127,8 @@ class ResponseBuilder {
if (response.code >= 500) {
log.error(
// eslint-disable-next-line sonarjs/no-nested-template-literals
`500+ error: ${req?.originalUrl} ${req?.user ? ` User ID: ${req?.user.id}` : ''} ${error.stack} ${
error.data ? JSON.stringify(error.data) : ''
}`
`500+ error: ${req?.originalUrl} ${req?.user ? ` User ID: ${req?.user.id}` : ''} ${error.stack} %o`,
error.data
);
}

Expand Down
84 changes: 0 additions & 84 deletions tests/middlewares/exception/formatters/index.unit.ts

This file was deleted.

Loading

0 comments on commit 3b4cdb5

Please sign in to comment.