Skip to content

Commit 46e43fc

Browse files
authored
docs: adds docs for logger config (#15927)
Fixes #11492
1 parent f30d34f commit 46e43fc

File tree

1 file changed

+80
-6
lines changed

1 file changed

+80
-6
lines changed

docs/configuration/overview.mdx

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The following options are available:
7777
| **`globals`** | An array of Globals for Payload to manage. [More details](./globals). |
7878
| **`cors`** | Cross-origin resource sharing (CORS) is a mechanism that accept incoming requests from given domains. You can also customize the `Access-Control-Allow-Headers` header. [More details](#cors). |
7979
| **`localization`** | Opt-in to translate your content into multiple locales. [More details](./localization). |
80-
| **`logger`** | Logger options, logger options with a destination stream, or an instantiated logger instance. [More details](https://getpino.io/#/docs/api?id=options). |
80+
| **`logger`** | Logger options, logger options with a destination stream, or an instantiated logger instance. [More details](#logger). |
8181
| **`loggingLevels`** | An object to override the level to use in the logger for Payload's errors. |
8282
| **`graphQL`** | Manage GraphQL-specific functionality, including custom queries and mutations, query complexity limits, etc. [More details](../graphql/overview#graphql-options). |
8383
| **`cookiePrefix`** | A string that will be prefixed to all cookies that Payload sets. |
@@ -131,11 +131,11 @@ export default buildConfig({
131131

132132
The following options are available:
133133

134-
| Option | Description |
135-
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
136-
| **`autoGenerate`** | By default, Payload will auto-generate TypeScript interfaces for all collections and globals that your config defines. Opt out by setting `typescript.autoGenerate: false`. [More details](../typescript/overview). |
137-
| **`declare`** | By default, Payload adds a `declare` block to your generated types, which makes sure that Payload uses your generated types for all Local API methods. Opt out by setting `typescript.declare: false`. |
138-
| **`outputFile`** | Control the output path and filename of Payload's auto-generated types by defining the `typescript.outputFile` property to a full, absolute path. |
134+
| Option | Description |
135+
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
136+
| **`autoGenerate`** | By default, Payload will auto-generate TypeScript interfaces for all collections and globals that your config defines. Opt out by setting `typescript.autoGenerate: false`. [More details](../typescript/overview). |
137+
| **`declare`** | By default, Payload adds a `declare` block to your generated types, which makes sure that Payload uses your generated types for all Local API methods. Opt out by setting `typescript.declare: false`. |
138+
| **`outputFile`** | Control the output path and filename of Payload's auto-generated types by defining the `typescript.outputFile` property to a full, absolute path. |
139139
| **`strictDraftTypes`** | Enable strict type safety for draft mode. When enabled: (1) Query operations (`find`, `findByID`) with `draft: true` will type required fields as optional, since validation is skipped for drafts. (2) The `draft` property is forbidden for collections without drafts in create operations. (3) Create operations enforce proper data requirements via discriminated unions. Defaults to `false`. **This will become the default behavior in v4.0.** |
140140

141141
## Config Location
@@ -277,6 +277,80 @@ Payload localization works on a field-by-field basis. As you can nest fields wit
277277

278278
By default, Payload will remove the `localized: true` property from sub-fields if a parent field is localized. Set this compatibility flag to `true` only if you have an existing Payload MongoDB database from pre-3.0, and you have nested localized fields that you would like to maintain without migrating.
279279

280+
## Logger
281+
282+
Payload uses [Pino](https://getpino.io) as its logger. By default, Payload logs pretty-printed output to stdout. You can customise this through the `logger` option in your config.
283+
284+
The `logger` option accepts one of three forms:
285+
286+
### 1. Logger options with an optional destination stream
287+
288+
Pass a `{ options, destination? }` object to configure the logger. `options` accepts standard [Pino logger options](https://getpino.io/#/docs/api?id=options) such as `level` and `name`. An optional `destination` stream can be supplied as a second argument.
289+
290+
```ts
291+
import { buildConfig } from 'payload'
292+
293+
export default buildConfig({
294+
// highlight-start
295+
logger: {
296+
options: {
297+
level: 'debug',
298+
},
299+
},
300+
// highlight-end
301+
})
302+
```
303+
304+
To write logs to a file, pass a destination stream:
305+
306+
```ts
307+
import { buildConfig } from 'payload'
308+
import { pino } from 'pino'
309+
310+
export default buildConfig({
311+
// highlight-start
312+
logger: {
313+
options: { level: 'info' },
314+
destination: pino.destination('/var/log/payload.log'),
315+
},
316+
// highlight-end
317+
})
318+
```
319+
320+
<Banner type="warning">
321+
**Compatibility note:** The `transport` property of Pino's `LoggerOptions` may
322+
fail with `"unable to determine transport target"` in some environments. Pino
323+
transports spawn a worker thread with their own module resolution, which can
324+
break when modules are bundled or the project uses ESM. If you encounter this
325+
error, use a pre-instantiated logger instead (see below).
326+
</Banner>
327+
328+
### 2. Pre-instantiated logger
329+
330+
Pass a fully configured Pino logger instance. This is the recommended approach when you need custom transports, formatters, or `pino-pretty` in development:
331+
332+
```ts
333+
import { buildConfig } from 'payload'
334+
import { pino } from 'pino'
335+
import pinoPretty from 'pino-pretty'
336+
337+
const logger = pino({ level: 'debug' }, pinoPretty({ colorize: true }))
338+
339+
export default buildConfig({
340+
// highlight-start
341+
logger,
342+
// highlight-end
343+
})
344+
```
345+
346+
### 3. Disabling logging
347+
348+
Set the `DISABLE_LOGGING` environment variable to `'true'` to suppress all log output:
349+
350+
```sh
351+
DISABLE_LOGGING=true node server.js
352+
```
353+
280354
## Custom bin scripts
281355

282356
Using the `bin` configuration property, you can inject your own scripts to `npx payload`.

0 commit comments

Comments
 (0)