forked from evmos/safe-client-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use JSON for logging (safe-global#310)
This PR is heavily inspired by 5afe/safe-gelato-relay-service#72 - Uses JSON as the default logging format – `winston.format.json()` is now the main formatter - The `ILoggingService` interface changed to accommodate the new format – a `message` can now be an unknown payload format or a `string` – regardless of the type, this value will be logged under `{ message: <value> }` - All the logging-related code is found under `src/logging` which makes it independent from the other service layers. The idea is to maintain the logging utilities as a shared service that can be injected on demand in other parts of the service. - The logging mechanism also adds `nestjs-cls` as a dependency to store request-wide data (like request ids). - Some redundant error messages were removed (`http-error.factory.ts` and `transaction-preview.mapper.ts` for example) since they would be logged twice with this new setup. The base format of the logs is as follows: ```javascript { message: <string | object>, // string value or json payload request_id: <string>, // id tied to the request timestamp: <string>, // ISO 8601 Date string } ``` The `message` value when logging route requests is as follows: ```javascript { ... message: { client_ip: <optional string>, // retrieved from the header X-Real-IP. null if not available method: <string>, // GET, POST, etc.. response_time_ms: <number>, // response time in milliseconds route: <optional string>, // route which handled the request. Null if no route handled this request (eg.: 404 requests) path: <string>, // path of the resource requested status_code: <number>, // resulting status code of the request detail: <optional string>, // optional message regarding the result of the request } } ```
- Loading branch information
1 parent
f17d5aa
commit 231a028
Showing
40 changed files
with
657 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Global, Module } from '@nestjs/common'; | ||
import { ILoggingService, LoggingService } from '../logging.interface'; | ||
|
||
const loggingService: ILoggingService = { | ||
info: console.log, | ||
error: console.error, | ||
warn: console.warn, | ||
debug: console.debug, | ||
}; | ||
|
||
const mockLoggingService = jest.mocked(loggingService); | ||
|
||
@Global() | ||
@Module({ | ||
providers: [{ provide: LoggingService, useValue: mockLoggingService }], | ||
exports: [LoggingService], | ||
}) | ||
export class TestLoggingModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const LoggingService = Symbol('ILoggingService'); | ||
|
||
export interface ILoggingService { | ||
info(message: string | unknown): void; | ||
|
||
debug(message: string | unknown): void; | ||
|
||
error(message: string | unknown): void; | ||
|
||
warn(message: string | unknown): void; | ||
} |
Oops, something went wrong.