@seek/logger
Advanced tools
Comparing version 6.1.1 to 6.2.0
@@ -29,3 +29,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pino = void 0; | ||
exports.pino = exports.DEFAULT_OMIT_HEADER_NAMES = void 0; | ||
const pino_1 = __importDefault(require("pino")); | ||
@@ -37,3 +37,5 @@ exports.pino = pino_1.default; | ||
const redact = __importStar(require("./redact")); | ||
const serializers_1 = __importDefault(require("./serializers")); | ||
const serializers_1 = require("./serializers"); | ||
var serializers_2 = require("./serializers"); | ||
Object.defineProperty(exports, "DEFAULT_OMIT_HEADER_NAMES", { enumerable: true, get: function () { return serializers_2.DEFAULT_OMIT_HEADER_NAMES; } }); | ||
/** | ||
@@ -52,4 +54,5 @@ * Creates a logger that can enforce a strict logged object shape. | ||
opts.redact = redact.addDefaultRedactPathStrings(opts.redact); | ||
const serializers = (0, serializers_1.createSerializers)(opts); | ||
opts.serializers = { | ||
...serializers_1.default, | ||
...serializers, | ||
...opts.serializers, | ||
@@ -56,0 +59,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSerializers = exports.DEFAULT_OMIT_HEADER_NAMES = void 0; | ||
const pino_std_serializers_1 = require("pino-std-serializers"); | ||
const omitPropertiesSerializer_1 = require("./omitPropertiesSerializer"); | ||
exports.DEFAULT_OMIT_HEADER_NAMES = Object.freeze([ | ||
'x-envoy-attempt-count', | ||
'x-envoy-decorator-operation', | ||
'x-envoy-expected-rq-timeout-ms', | ||
'x-envoy-external-address', | ||
'x-envoy-internal', | ||
'x-envoy-peer-metadata', | ||
'x-envoy-peer-metadata-id', | ||
'x-envoy-upstream-service-time', | ||
]); | ||
const getHeaders = ({ _header, header, headers }) => _header || header || headers; | ||
@@ -10,7 +22,7 @@ const getStatus = ({ statusCode, status }) => statusCode ?? status; | ||
}; | ||
const req = (request) => isObject(request) | ||
const createReqSerializer = (serializeHeaders) => (request) => isObject(request) | ||
? { | ||
method: request.method, | ||
url: request.url, | ||
headers: request.headers, | ||
headers: serializeHeaders(request.headers), | ||
remoteAddress: request?.socket?.remoteAddress, | ||
@@ -26,8 +38,14 @@ remotePort: request?.socket?.remotePort, | ||
: response; | ||
exports.default = { | ||
err: pino_std_serializers_1.err, | ||
errWithCause: pino_std_serializers_1.errWithCause, | ||
res, | ||
req, | ||
const createSerializers = (opts) => { | ||
const serializeHeaders = (0, omitPropertiesSerializer_1.createOmitPropertiesSerializer)(opts.omitHeaderNames ?? exports.DEFAULT_OMIT_HEADER_NAMES); | ||
const serializers = { | ||
err: pino_std_serializers_1.err, | ||
errWithCause: pino_std_serializers_1.errWithCause, | ||
req: createReqSerializer(serializeHeaders), | ||
res, | ||
headers: serializeHeaders, | ||
}; | ||
return serializers; | ||
}; | ||
exports.createSerializers = createSerializers; | ||
//# sourceMappingURL=index.js.map |
@@ -6,3 +6,4 @@ import pino from 'pino'; | ||
import * as redact from './redact'; | ||
import serializers from './serializers'; | ||
import { createSerializers } from './serializers'; | ||
export { DEFAULT_OMIT_HEADER_NAMES } from './serializers'; | ||
export { pino }; | ||
@@ -22,2 +23,3 @@ /** | ||
opts.redact = redact.addDefaultRedactPathStrings(opts.redact); | ||
const serializers = createSerializers(opts); | ||
opts.serializers = { | ||
@@ -24,0 +26,0 @@ ...serializers, |
import { err, errWithCause } from 'pino-std-serializers'; | ||
import { createOmitPropertiesSerializer } from './omitPropertiesSerializer'; | ||
export const DEFAULT_OMIT_HEADER_NAMES = Object.freeze([ | ||
'x-envoy-attempt-count', | ||
'x-envoy-decorator-operation', | ||
'x-envoy-expected-rq-timeout-ms', | ||
'x-envoy-external-address', | ||
'x-envoy-internal', | ||
'x-envoy-peer-metadata', | ||
'x-envoy-peer-metadata-id', | ||
'x-envoy-upstream-service-time', | ||
]); | ||
const getHeaders = ({ _header, header, headers }) => _header || header || headers; | ||
@@ -8,7 +19,7 @@ const getStatus = ({ statusCode, status }) => statusCode ?? status; | ||
}; | ||
const req = (request) => isObject(request) | ||
const createReqSerializer = (serializeHeaders) => (request) => isObject(request) | ||
? { | ||
method: request.method, | ||
url: request.url, | ||
headers: request.headers, | ||
headers: serializeHeaders(request.headers), | ||
remoteAddress: request?.socket?.remoteAddress, | ||
@@ -24,8 +35,13 @@ remotePort: request?.socket?.remotePort, | ||
: response; | ||
export default { | ||
err, | ||
errWithCause, | ||
res, | ||
req, | ||
export const createSerializers = (opts) => { | ||
const serializeHeaders = createOmitPropertiesSerializer(opts.omitHeaderNames ?? DEFAULT_OMIT_HEADER_NAMES); | ||
const serializers = { | ||
err, | ||
errWithCause, | ||
req: createReqSerializer(serializeHeaders), | ||
res, | ||
headers: serializeHeaders, | ||
}; | ||
return serializers; | ||
}; | ||
//# sourceMappingURL=index.js.map |
import type { LoggerOptions } from 'pino'; | ||
import type pino from 'pino'; | ||
export interface FormatterOptions { | ||
@@ -13,2 +12,2 @@ /** | ||
} | ||
export declare const createFormatters: (opts: FormatterOptions & Pick<LoggerOptions, 'serializers'>) => pino.LoggerOptions['formatters']; | ||
export declare const createFormatters: (opts: FormatterOptions & Pick<LoggerOptions, 'serializers'>) => LoggerOptions['formatters']; |
import pino from 'pino'; | ||
import { type FormatterOptions } from './formatters'; | ||
import { type SerializerOptions } from './serializers'; | ||
export { DEFAULT_OMIT_HEADER_NAMES } from './serializers'; | ||
export { pino }; | ||
export type LoggerOptions = pino.LoggerOptions & FormatterOptions; | ||
export type LoggerOptions = pino.LoggerOptions & FormatterOptions & SerializerOptions; | ||
export type Logger = pino.Logger; | ||
@@ -6,0 +8,0 @@ /** |
import { err, errWithCause } from 'pino-std-serializers'; | ||
import type { SerializerFn } from './types'; | ||
export declare const DEFAULT_OMIT_HEADER_NAMES: readonly string[]; | ||
export interface SerializerOptions { | ||
/** | ||
* The request headers to omit from serialized logs. | ||
* | ||
* The properties listed will be removed under `headers` and `req.headers`. | ||
* Matching is currently case sensitive. | ||
* You will typically express the header names in lowercase, | ||
* as server frameworks normalise incoming headers. | ||
* | ||
* You can use this option to reduce logging costs. | ||
* Defaults to `DEFAULT_OMIT_HEADER_NAMES`, | ||
* and can be disabled by supplying an empty array `[]`. | ||
*/ | ||
omitHeaderNames?: readonly string[]; | ||
} | ||
interface Socket { | ||
@@ -10,3 +27,3 @@ remoteAddress?: string; | ||
headers: Record<string, string>; | ||
socket: Socket; | ||
socket?: Socket; | ||
} | ||
@@ -17,14 +34,15 @@ interface Response extends Record<string, unknown> { | ||
} | ||
declare const _default: { | ||
export declare const createSerializers: (opts: SerializerOptions) => { | ||
err: typeof err; | ||
errWithCause: typeof errWithCause; | ||
res: (response: Response) => Response; | ||
req: (request: Request) => Request | { | ||
method: string; | ||
url: string; | ||
headers: Record<string, string>; | ||
headers: unknown; | ||
remoteAddress: string | undefined; | ||
remotePort: string | undefined; | ||
}; | ||
res: (response: Response) => Response; | ||
headers: SerializerFn; | ||
}; | ||
export default _default; | ||
export {}; |
{ | ||
"name": "@seek/logger", | ||
"version": "6.1.1", | ||
"version": "6.2.0", | ||
"private": false, | ||
@@ -33,4 +33,4 @@ "description": "Standardized logging", | ||
"lint": "skuba lint", | ||
"prepush": "yarn test", | ||
"release": "yarn build && skuba release", | ||
"release": "yarn build && changeset publish", | ||
"stage": "changeset version && yarn format", | ||
"test": "skuba test", | ||
@@ -45,4 +45,6 @@ "test:ci": "skuba test --coverage" | ||
"devDependencies": { | ||
"@types/split2": "4.2.0", | ||
"skuba": "7.1.1", | ||
"@changesets/cli": "2.26.2", | ||
"@changesets/get-github-info": "0.5.2", | ||
"@types/split2": "4.2.1", | ||
"skuba": "7.2.0", | ||
"split2": "4.2.0" | ||
@@ -49,0 +51,0 @@ }, |
@@ -7,3 +7,2 @@ # @seek/logger | ||
[![npm package](https://img.shields.io/npm/v/@seek/logger)](https://www.npmjs.com/package/@seek/logger) | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) | ||
@@ -50,3 +49,3 @@ **@seek/logger** is a JSON logger for Node.js applications. | ||
**@seek/logger** bundles custom `req` and `res` serializers along with [Pino]'s standard set. | ||
**@seek/logger** bundles custom `req`, `res` and `headers` serializers along with [Pino]'s standard set. | ||
User-defined serializers will take precedence over predefined ones. | ||
@@ -63,3 +62,6 @@ | ||
The request object is trimmed to a set of essential fields. | ||
The request object is trimmed to a set of essential fields. | ||
Certain headers are omitted by default (e.g. `x-envoy-peer-metadata`). | ||
To opt out of this behavior, set the `omitHeaderNames` logger option to an empty list `[]` | ||
or provide your own list. | ||
@@ -70,2 +72,8 @@ - `res` for HTTP responses. | ||
- `headers` for tracing headers. | ||
Certain headers are omitted by default (e.g. `x-envoy-peer-metadata`). | ||
To opt out of this behavior, set the `omitHeaderNames` logger option to an empty list `[]` | ||
or provide your own list. | ||
All other fields will be logged directly. | ||
@@ -72,0 +80,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35593
48
444
173
5