-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cedbca
commit 17fc322
Showing
19 changed files
with
2,814 additions
and
1,814 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
### Logger usage | ||
|
||
The project uses `pino` logger. This logger should be used over `console` calls. | ||
|
||
For usual in-file logging one should import the logger from the corresponding `logger.ts` module | ||
and use it in accordance with [documentation](https://github.com/pinojs/pino/tree/master/docs). | ||
|
||
In case of logging the processes that happen during http request handling it is also | ||
possible to use the dedicated logger that is accessible via the `express` request object. | ||
|
||
Here's a couple of examples: | ||
|
||
1. Http logging | ||
|
||
```typescript | ||
// some resolver code above | ||
resolve: (_parent, _args, ctx) => { | ||
ctx.apolloLogger.debug('resolver called'); | ||
}); | ||
}, | ||
|
||
``` | ||
|
||
2. Usual logger | ||
|
||
In order to maintain the logging structure and be able to filter logs by file they have been produced at the following approach has to be taken: | ||
|
||
```typescript | ||
import { getModuleBinding, getChildLogger } from './logger'; | ||
|
||
const logger = getChildLogger({ msgPrefix: 'PREFIX' }, { myCustomBinding: 'Funny guy' }); | ||
``` | ||
|
||
If this approach is used - then it will be possible to filter the logs via providing the corresponding environment variable values. For more on this read the root [README](./README.md) |
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,35 @@ | ||
import { LoggerConfig } from './src/types'; | ||
|
||
export const defaultLoggerConfig: LoggerConfig = { | ||
// Filter by module name | ||
moduleFilter: [], | ||
// Filter by log prefix, e.g. adding | ||
// `pref` to filter is going to correspond to showing `[PREF] ` logs | ||
prefixFilter: [], | ||
// Lowest printed log level of default logger | ||
logLevel: 'info', | ||
// Log levels of prisma logger that are enabled | ||
dbLogLevel: ['info'], | ||
// Lowest printed log level of express logger | ||
httpLogLevel: 'info', | ||
}; | ||
|
||
export const debugLogConfig: LoggerConfig = { | ||
// Filter by module name | ||
moduleFilter: [], | ||
// Filter by log prefix, e.g. adding | ||
// `pref` to filter is going to correspond to showing `[PERF]` logs | ||
prefixFilter: [], | ||
// Lowest printed log level of default logger | ||
logLevel: 'debug', | ||
// Log levels of prisma logger that are enabled | ||
dbLogLevel: ['query'], | ||
// Lowest printed log level of express logger | ||
httpLogLevel: 'debug', | ||
}; | ||
|
||
function getLoggerConfig(debug: boolean): LoggerConfig { | ||
return (debug ? debugLogConfig : defaultLoggerConfig); | ||
} | ||
|
||
export const loggerConfig = getLoggerConfig(!!process.env.DEBUG); |
Oops, something went wrong.