Skip to content

Commit

Permalink
Use transport instead of prettyPrint
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil committed Oct 11, 2023
1 parent a7a4536 commit 8bc815b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ await server.register({
```

This will log JSON'ified response entries to `stdout`, and server and request events to `stderr`.
To make the logs prettier while developing, install the `pino-pretty` module, and enable it using the `prettyPrint` pino option.
To make the logs prettier while developing, install the `pino-pretty` module, and enable it using the `transport` pino option.
10 changes: 2 additions & 8 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Stream } from 'node:stream';
import { Plugin, Request } from '@hapi/hapi';
import { Logger, LoggerOptions, Level } from 'pino';

type AllowedPinoOptions = 'name' | 'level' | 'redact' | 'formatters' | 'enabled' | 'crlf' | 'timestamp' | 'messageKey';
type AllowedPinoOptions = 'name' | 'level' | 'redact' | 'formatters' | 'enabled' | 'crlf' | 'timestamp' | 'messageKey' | 'transport';

export interface NipoRegistrationOptions {

Expand Down Expand Up @@ -33,13 +33,7 @@ export interface NipoRegistrationOptions {
/**
* Pino logger options passed to constructor.
*/
pino?: Pick<LoggerOptions, AllowedPinoOptions> & {

/**
* Use pino-pretty for output formatting.
*/
prettyPrint?: boolean;
};
pino?: Pick<LoggerOptions, AllowedPinoOptions>;
}

export const plugin: Plugin<NipoRegistrationOptions> & {
Expand Down
19 changes: 16 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ internals.errSerializer = function (error) {
internals.pinoLevels = Pino().levels;


const baseTargetSchema = Joi.object({
target: Joi.string(),
options: Joi.object().unknown().optional()
});


internals.optionsSchema = Joi.object({
logResponse: Joi.func(),
tagLevels: Joi.object().pattern(
Expand Down Expand Up @@ -247,9 +253,16 @@ internals.optionsSchema = Joi.object({
crlf: Joi.boolean(),
timestamp: Joi.alternatives().try(Joi.boolean(), Joi.func()).default(true),
messageKey: Joi.string(),
//$lab:coverage:off$
prettyPrint: internals.hasPretty ? Joi.boolean() : Joi.boolean().equal(false)
//$lab:coverage:on$
transport: Joi.alternatives().try(
baseTargetSchema.append({
targets: Joi.array().items(baseTargetSchema.append({
level: Joi.string()
})),
pipeline: Joi.array().items(baseTargetSchema),
worker: Joi.object().unknown(),
dedupe: Joi.boolean()
}).xor('target', 'targets', 'pipeline')
)
}).default({})
}).strict();

Expand Down
2 changes: 1 addition & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ await server.register({
test: 'debug'
},
pino: {
prettyPrint: false
level: 'info'
}
}
});
Expand Down

0 comments on commit 8bc815b

Please sign in to comment.