Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pinojs/pino
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v9.5.0
Choose a base ref
...
head repository: pinojs/pino
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v9.6.0
Choose a head ref
  • 18 commits
  • 12 files changed
  • 13 contributors

Commits on Oct 19, 2024

  1. build(deps-dev): lock typescript minor version (#2066)

    Fdawgs authored Oct 19, 2024
    Copy the full SHA
    77fbf34 View commit details

Commits on Oct 21, 2024

  1. build(deps-dev): bump typescript from 5.1.6 to 5.6.3 (#2068)

    Bumps [typescript](https://github.com/microsoft/TypeScript) from 5.1.6 to 5.6.3.
    - [Release notes](https://github.com/microsoft/TypeScript/releases)
    - [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml)
    - [Commits](microsoft/TypeScript@v5.1.6...v5.6.3)
    
    ---
    updated-dependencies:
    - dependency-name: typescript
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Oct 21, 2024
    Copy the full SHA
    0748175 View commit details

Commits on Oct 28, 2024

  1. docs: update pino-datadog-transport repository (#2069)

    MathewBoyles authored Oct 28, 2024
    Copy the full SHA
    fb8bd61 View commit details
  2. build(deps-dev): bump @yao-pkg/pkg from 5.15.0 to 6.0.0 (#2070)

    Bumps [@yao-pkg/pkg](https://github.com/yao-pkg/pkg) from 5.15.0 to 6.0.0.
    - [Release notes](https://github.com/yao-pkg/pkg/releases)
    - [Changelog](https://github.com/yao-pkg/pkg/blob/main/CHANGELOG.md)
    - [Commits](yao-pkg/pkg@v5.15.0...v6.0.0)
    
    ---
    updated-dependencies:
    - dependency-name: "@yao-pkg/pkg"
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Oct 28, 2024
    Copy the full SHA
    231adff View commit details

Commits on Nov 4, 2024

  1. build(deps-dev): bump @yao-pkg/pkg from 6.0.0 to 6.0.1 (#2075)

    Bumps [@yao-pkg/pkg](https://github.com/yao-pkg/pkg) from 6.0.0 to 6.0.1.
    - [Release notes](https://github.com/yao-pkg/pkg/releases)
    - [Changelog](https://github.com/yao-pkg/pkg/blob/main/CHANGELOG.md)
    - [Commits](yao-pkg/pkg@v6.0.0...v6.0.1)
    
    ---
    updated-dependencies:
    - dependency-name: "@yao-pkg/pkg"
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 4, 2024
    Copy the full SHA
    b3974ed View commit details

Commits on Nov 11, 2024

  1. build(deps-dev): bump @yao-pkg/pkg from 6.0.1 to 6.1.0 (#2082)

    Bumps [@yao-pkg/pkg](https://github.com/yao-pkg/pkg) from 6.0.1 to 6.1.0.
    - [Release notes](https://github.com/yao-pkg/pkg/releases)
    - [Changelog](https://github.com/yao-pkg/pkg/blob/main/CHANGELOG.md)
    - [Commits](yao-pkg/pkg@v6.0.1...v6.1.0)
    
    ---
    updated-dependencies:
    - dependency-name: "@yao-pkg/pkg"
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 11, 2024
    Copy the full SHA
    9047cd9 View commit details

Commits on Nov 18, 2024

  1. build(deps-dev): bump airtap from 4.0.4 to 5.0.0 (#2090)

    Bumps [airtap](https://github.com/airtap/airtap) from 4.0.4 to 5.0.0.
    - [Release notes](https://github.com/airtap/airtap/releases)
    - [Changelog](https://github.com/airtap/airtap/blob/main/CHANGELOG.md)
    - [Commits](airtap/airtap@v4.0.4...v5.0.0)
    
    ---
    updated-dependencies:
    - dependency-name: airtap
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 18, 2024
    Copy the full SHA
    90b0d97 View commit details
  2. build(deps-dev): bump @yao-pkg/pkg from 6.1.0 to 6.1.1 (#2091)

    Bumps [@yao-pkg/pkg](https://github.com/yao-pkg/pkg) from 6.1.0 to 6.1.1.
    - [Release notes](https://github.com/yao-pkg/pkg/releases)
    - [Changelog](https://github.com/yao-pkg/pkg/blob/main/CHANGELOG.md)
    - [Commits](yao-pkg/pkg@v6.1.0...v6.1.1)
    
    ---
    updated-dependencies:
    - dependency-name: "@yao-pkg/pkg"
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 18, 2024
    Copy the full SHA
    3505a68 View commit details
  3. docs: add @openobserve/openobserve-pino transports (#2078)

    * add @openobserve/openobserve-pino to transports.md
    
    * Update transports.md
    
    * Update docs/transports.md
    
    Co-authored-by: James Sumners <[email protected]>
    
    * Update docs/transports.md
    
    Co-authored-by: James Sumners <[email protected]>
    
    ---------
    
    Co-authored-by: James Sumners <[email protected]>
    ktx-kirtan and jsumners authored Nov 18, 2024
    Copy the full SHA
    4ea00c2 View commit details

Commits on Nov 22, 2024

  1. docs: add missing parenthesis to transport code example (#2099)

    Co-authored-by: thsmale <[email protected]>
    thsmale and thsmale authored Nov 22, 2024
    Copy the full SHA
    806ea86 View commit details
  2. docs: alphabetize ecosystem lists (#2097)

    ChinoUkaegbu authored Nov 22, 2024
    Copy the full SHA
    9434f38 View commit details

Commits on Nov 25, 2024

  1. build(deps-dev): bump typescript from 5.6.3 to 5.7.2 (#2101)

    Bumps [typescript](https://github.com/microsoft/TypeScript) from 5.6.3 to 5.7.2.
    - [Release notes](https://github.com/microsoft/TypeScript/releases)
    - [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml)
    - [Commits](microsoft/TypeScript@v5.6.3...v5.7.2)
    
    ---
    updated-dependencies:
    - dependency-name: typescript
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 25, 2024
    Copy the full SHA
    d1c3b9f View commit details

Commits on Dec 9, 2024

  1. chore(docs): add links to gcp logging formatter (#2088)

    Co-authored-by: nielm <Niel Markwick>
    nielm authored Dec 9, 2024
    Copy the full SHA
    182002c View commit details

Commits on Dec 10, 2024

  1. docs: update API reference (#2095)

    Signed-off-by: Emmanuel Ferdman <[email protected]>
    emmanuel-ferdman authored Dec 10, 2024
    Copy the full SHA
    1bff08a View commit details

Commits on Dec 14, 2024

  1. add new streamWrite hook (#2105)

    theoephraim authored Dec 14, 2024
    Copy the full SHA
    bb1f89d View commit details

Commits on Dec 23, 2024

  1. test: use fs.execFile instead of exec (#2110)

    * test: use fs.execFile instead of exec
    
    Generally safer than building a shell script, and allows to run the
    tests from a directory with spaces in it.
    
    * fix windows
    
    * use shell
    targos authored Dec 23, 2024
    Copy the full SHA
    abd6621 View commit details
  2. Bumped v9.6.0

    Signed-off-by: Matteo Collina <[email protected]>
    mcollina committed Dec 23, 2024
    Copy the full SHA
    6bf9478 View commit details
  3. test: skip pkg test in CITGM (#2112)

    targos authored Dec 23, 2024
    Copy the full SHA
    4df424c View commit details
Showing with 138 additions and 28 deletions.
  1. +17 −0 docs/api.md
  2. +13 −12 docs/ecosystem.md
  3. +28 −2 docs/help.md
  4. +32 −2 docs/transports.md
  5. +1 −1 lib/meta.js
  6. +4 −2 lib/proto.js
  7. +4 −4 package.json
  8. +6 −0 pino.d.ts
  9. +2 −1 pino.js
  10. +21 −0 test/hooks.test.js
  11. +6 −4 test/pkg/pkg.test.js
  12. +4 −0 test/types/pino.test-d.ts
17 changes: 17 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -375,6 +375,23 @@ const hooks = {
}
```


<a id="streamWrite"></a>
##### `streamWrite`

Allows for manipulating the _stringified_ JSON log data just before writing to various transports.

The method receives the stringified JSON and must return valid stringified JSON.

For example:
```js
const hooks = {
streamWrite (s) {
return s.replaceAll('sensitive-api-key', 'XXX')
}
}
```

<a id=opt-formatters></a>
#### `formatters` (Object)

25 changes: 13 additions & 12 deletions docs/ecosystem.md
Original file line number Diff line number Diff line change
@@ -16,10 +16,10 @@ Please send a PR to add new modules!
Pino to log requests within [express](https://expressjs.com/).
+ [`koa-pino-logger`](https://github.com/pinojs/koa-pino-logger): use Pino to
log requests within [Koa](https://koajs.com/).
+ [`rill-pino-logger`](https://github.com/pinojs/rill-pino-logger): use Pino as
the logger for the [Rill framework](https://rill.site/).
+ [`restify-pino-logger`](https://github.com/pinojs/restify-pino-logger): use
Pino to log requests within [restify](http://restify.com/).
+ [`rill-pino-logger`](https://github.com/pinojs/rill-pino-logger): use Pino as
the logger for the [Rill framework](https://rill.site/).

### Utilities
+ [`pino-arborsculpture`](https://github.com/pinojs/pino-arborsculpture): change
@@ -43,10 +43,10 @@ for [Hapi](https://hapijs.com/).
requests with the core `http` module.
+ [`pino-http-print`](https://github.com/pinojs/pino-http-print): reformat Pino
logs into traditional [HTTPD](https://httpd.apache.org/) style request logs.
+ [`pino-multi-stream`](https://github.com/pinojs/pino-multi-stream): send
logs to multiple destination streams (slow!).
+ [`pino-mongodb`](https://github.com/pinojs/pino-mongodb): store Pino logs
in a MongoDB database.
+ [`pino-multi-stream`](https://github.com/pinojs/pino-multi-stream): send
logs to multiple destination streams (slow!).
+ [`pino-noir`](https://github.com/pinojs/pino-noir): redact sensitive information
in logs.
+ [`pino-pretty`](https://github.com/pinojs/pino-pretty): basic prettifier to
@@ -59,25 +59,26 @@ core object serializers used within Pino.
to standard syslog format.
+ [`pino-tee`](https://github.com/pinojs/pino-tee): pipe Pino logs into files
based upon log levels.
+ [`pino-toke`](https://github.com/pinojs/pino-toke): reformat Pino logs
according to a given format string.
+ [`pino-test`](https://github.com/pinojs/pino-test): a set of utilities for
verifying logs generated by the Pino logger.
+ [`pino-toke`](https://github.com/pinojs/pino-toke): reformat Pino logs
according to a given format string.


<a id="community"></a>
## Community

+ [`@google-cloud/pino-logging-gcp-config`](https://www.npmjs.com/package/@google-cloud/pino-logging-gcp-config): Config helper and formatter to output [Google Cloud Platform Structured Logging](https://cloud.google.com/logging/docs/structured-logging)
+ [`@newrelic/pino-enricher`](https://github.com/newrelic/newrelic-node-log-extensions/blob/main/packages/pino-log-enricher): a log customization to add New Relic context to use [Logs In Context](https://docs.newrelic.com/docs/logs/logs-context/logs-in-context/)
+ [`cloud-pine`](https://github.com/metcoder95/cloud-pine): transport that provides abstraction and compatibility with [`@google-cloud/logging`](https://www.npmjs.com/package/@google-cloud/logging).
+ [`cls-proxify`](https://github.com/keenondrums/cls-proxify): integration of pino and [CLS](https://github.com/jeff-lewis/cls-hooked). Useful for creating dynamically configured child loggers (e.g. with added trace ID) for each request.
+ [`crawlee-pino`](https://github.com/imyelo/crawlee-pino): use Pino to log within Crawlee
+ [`pino-colada`](https://github.com/lrlna/pino-colada): cute ndjson formatter for pino.
+ [`pino-dev`](https://github.com/dnjstrom/pino-dev): simple prettifier for pino with built-in support for common ecosystem packages.
+ [`pino-fluentd`](https://github.com/davidedantonio/pino-fluentd): send Pino logs to Elasticsearch,
MongoDB, and many [others](https://www.fluentd.org/dataoutputs) via Fluentd.
+ [`pino-lambda`](https://github.com/FormidableLabs/pino-lambda): log transport for cloudwatch support inside aws-lambda
+ [`pino-pretty-min`](https://github.com/unjello/pino-pretty-min): a minimal
prettifier inspired by the [logrus](https://github.com/sirupsen/logrus) logger.
+ [`pino-rotating-file`](https://github.com/homeaway/pino-rotating-file): a hapi-pino log transport for splitting logs into separate, automatically rotating files.
+ [`cls-proxify`](https://github.com/keenondrums/cls-proxify): integration of pino and [CLS](https://github.com/jeff-lewis/cls-hooked). Useful for creating dynamically configured child loggers (e.g. with added trace ID) for each request.
+ [`pino-tiny`](https://github.com/holmok/pino-tiny): a tiny (and extensible?) little log formatter for pino.
+ [`pino-dev`](https://github.com/dnjstrom/pino-dev): simple prettifier for pino with built-in support for common ecosystem packages.
+ [`@newrelic/pino-enricher`](https://github.com/newrelic/newrelic-node-log-extensions/blob/main/packages/pino-log-enricher): a log customization to add New Relic context to use [Logs In Context](https://docs.newrelic.com/docs/logs/logs-context/logs-in-context/)
+ [`pino-lambda`](https://github.com/FormidableLabs/pino-lambda): log transport for cloudwatch support inside aws-lambda
+ [`cloud-pine`](https://github.com/metcoder95/cloud-pine): transport that provides abstraction and compatibility with [`@google-cloud/logging`](https://www.npmjs.com/package/@google-cloud/logging).
+ [`crawlee-pino`](https://github.com/imyelo/crawlee-pino): use Pino to log within Crawlee
30 changes: 28 additions & 2 deletions docs/help.md
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ ExecStart=/bin/sh -c '/path/to/node app.js | pino-transport'
Pino's default log destination is the singular destination of `stdout`. While
not recommended for performance reasons, multiple destinations can be targeted
by using [`pino.multistream`](/doc/api.md#pino-multistream).
by using [`pino.multistream`](/docs/api.md#pino-multistream).
In this example, we use `stderr` for `error` level logs and `stdout` as default
for all other levels (e.g. `debug`, `info`, and `warn`).
@@ -260,6 +260,32 @@ module.exports = function createLogger(options) {
}
```

A library that configures Pino for
[Google Cloud Structured Logging](https://cloud.google.com/logging/docs/structured-logging)
is available at:
[@google-cloud/pino-logging-gcp-config](https://www.npmjs.com/package/@google-cloud/pino-logging-gcp-config)

This library has the following features:

+ Converts Pino log levels to Google Cloud Logging log levels, as above
+ Uses `message` instead of `msg` for the message key, as above
+ Adds a millisecond-granularity timestamp in the
[structure](https://cloud.google.com/logging/docs/agent/logging/configuration#timestamp-processing)
recognised by Google Cloud Logging eg: \
`"timestamp":{"seconds":1445470140,"nanos":123000000}`
+ Adds a sequential
[`insertId`](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.insert_id)
to ensure log messages with identical timestamps are ordered correctly.
+ Logs including an `Error` object have the
[`stack_trace`](https://cloud.google.com/error-reporting/docs/formatting-error-messages#log-error)
property set so that the error is forwarded to Google Cloud Error Reporting.
+ Includes a
[`ServiceContext`](https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext)
object in the logs for Google Cloud Error Reporting, auto detected from the
environment if not specified
+ Maps the OpenTelemetry properties `span_id`, `trace_id`, and `trace_flags`
to the equivalent Google Cloud Logging fields.

<a id="grafana-loki"></a>
## Using Grafana Loki to evaluate pino logs in a kubernetes cluster

@@ -316,4 +342,4 @@ if you have broader logging requirements.
<a id="testing"></a>
## Testing

See [`pino-test`](https://github.com/pinojs/pino-test).
See [`pino-test`](https://github.com/pinojs/pino-test).
34 changes: 32 additions & 2 deletions docs/transports.md
Original file line number Diff line number Diff line change
@@ -222,7 +222,7 @@ In case you want to both use a custom transport, and output the log entries with
}
]

const logger = pino(pino.transport({ targets: transports })
const logger = pino(pino.transport({ targets: transports }))
```
### Creating a transport pipeline
@@ -426,6 +426,7 @@ PRs to this document are welcome for any new transports!
+ [@axiomhq/pino](#@axiomhq/pino)
+ [@logtail/pino](#@logtail/pino)
+ [@macfja/pino-fingers-crossed](#macfja-pino-fingers-crossed)
+ [@openobserve/pino-openobserve](#pino-openobserve)
+ [pino-airbrake-transport](#pino-airbrake-transport)
+ [pino-axiom](#pino-axiom)
+ [pino-datadog-transport](#pino-datadog-transport)
@@ -525,6 +526,35 @@ logger.info('Will NOT appear')
logger.info({ [enable]: false }, 'Will appear immedialty')
logger.info('Will NOT appear')
```
<a id="pino-openobserve"></a>
### @openobserve/pino-openobserve
[@openobserve/pino-openobserve](https://github.com/openobserve/pino-openobserve) is a
Pino v7+ transport that will send logs to an
[OpenObserve](https://openobserve.ai) instance.
```
const pino = require('pino');
const OpenobserveTransport = require('@openobserve/pino-openobserve');

const logger = pino({
level: 'info',
transport: {
target: OpenobserveTransport,
options: {
url: 'https://your-openobserve-server.com',
organization: 'your-organization',
streamName: 'your-stream',
auth: {
username: 'your-username',
password: 'your-password',
},
},
},
});
```
For full documentation check the [README](https://github.com/openobserve/pino-openobserve).
<a id="pino-airbrake-transport"></a>
### pino-airbrake-transport
@@ -653,7 +683,7 @@ const transport = pino.transport({
pino(transport)
```
[pino-datadog-transport]: https://github.com/theogravity/pino-datadog-transport
[pino-datadog-transport]: https://github.com/theogravity/datadog-transports
[Datadog]: https://www.datadoghq.com/
#### Logstash
2 changes: 1 addition & 1 deletion lib/meta.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict'

module.exports = { version: '9.5.0' }
module.exports = { version: '9.6.0' }
6 changes: 4 additions & 2 deletions lib/proto.js
Original file line number Diff line number Diff line change
@@ -27,7 +27,8 @@ const {
stringifySym,
formatOptsSym,
stringifiersSym,
msgPrefixSym
msgPrefixSym,
hooksSym
} = require('./symbols')
const {
getLevel,
@@ -185,6 +186,7 @@ function write (_obj, msg, num) {
const messageKey = this[messageKeySym]
const mixinMergeStrategy = this[mixinMergeStrategySym] || defaultMixinMergeStrategy
let obj
const streamWriteHook = this[hooksSym].streamWrite

if (_obj === undefined || _obj === null) {
obj = {}
@@ -214,7 +216,7 @@ function write (_obj, msg, num) {
stream.lastTime = t.slice(this[timeSliceIndexSym])
stream.lastLogger = this // for child loggers
}
stream.write(s)
stream.write(streamWriteHook ? streamWriteHook(s) : s)
}

function noop () {}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pino",
"version": "9.5.0",
"version": "9.6.0",
"description": "super fast, all natural json logger",
"main": "pino.js",
"type": "commonjs",
@@ -63,8 +63,8 @@
"@types/flush-write-stream": "^1.0.0",
"@types/node": "^22.0.0",
"@types/tap": "^15.0.6",
"@yao-pkg/pkg": "5.15.0",
"airtap": "4.0.4",
"@yao-pkg/pkg": "6.1.1",
"airtap": "5.0.0",
"benchmark": "^2.1.4",
"bole": "^5.0.5",
"bunyan": "^1.8.14",
@@ -98,7 +98,7 @@
"through2": "^4.0.0",
"ts-node": "^10.9.1",
"tsd": "^0.31.0",
"typescript": "^5.1.3",
"typescript": "~5.7.2",
"winston": "^3.7.2"
},
"dependencies": {
6 changes: 6 additions & 0 deletions pino.d.ts
Original file line number Diff line number Diff line change
@@ -641,6 +641,12 @@ declare namespace pino {
* using apply, like so: method.apply(this, newArgumentsArray).
*/
logMethod?: (this: Logger, args: Parameters<LogFn>, method: LogFn, level: number) => void;

/**
* Allows for manipulating the stringified JSON log output just before writing to various transports.
* This function must return a string and must be valid JSON.
*/
streamWrite?: (s: string) => string;
};

/**
3 changes: 2 additions & 1 deletion pino.js
Original file line number Diff line number Diff line change
@@ -70,7 +70,8 @@ const defaultOptions = {
}
}),
hooks: {
logMethod: undefined
logMethod: undefined,
streamWrite: undefined
},
timestamp: epochTime,
name: undefined,
21 changes: 21 additions & 0 deletions test/hooks.test.js
Original file line number Diff line number Diff line change
@@ -95,3 +95,24 @@ tap.test('log method hook', t => {

t.end()
})

tap.test('streamWrite hook', t => {
t.test('gets invoked', async t => {
t.plan(1)

const stream = sink()
const logger = pino({
hooks: {
streamWrite (s) {
return s.replaceAll('redact-me', 'XXX')
}
}
}, stream)

const o = once(stream, 'data')
logger.info('hide redact-me in this string')
t.match(await o, { msg: 'hide XXX in this string' })
})

t.end()
})
10 changes: 6 additions & 4 deletions test/pkg/pkg.test.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@ const { promisify } = require('node:util')
const { unlink } = require('node:fs/promises')
const { join } = require('node:path')
const { platform } = require('node:process')
const exec = promisify(require('node:child_process').exec)
const execFile = promisify(require('node:child_process').execFile)

const skip = process.env.PNPM_CI || process.env.CITGM

/**
* The following regex is for tesintg the deprecation warning that is thrown by the `punycode` module.
@@ -18,13 +20,13 @@ const exec = promisify(require('node:child_process').exec)
*/
const deprecationWarningRegex = /^\(\w+:\d+\)\s\[[\w|\d]+\]\sDeprecationWarning: The `punycode` module is deprecated\.\s+Please use a userland alternative instead\.\s+\(Use `node --trace-deprecation \.\.\.` to show where the warning was created\)\s+$/

test('worker test when packaged into executable using pkg', { skip: !!process.env.PNPM_CI }, async (t) => {
test('worker test when packaged into executable using pkg', { skip }, async (t) => {
const packageName = 'index'

// package the app into several node versions, check config for more info
const filePath = `${join(__dirname, packageName)}.js`
const configPath = join(__dirname, 'pkg.config.json')
const { stderr } = await exec(`npx pkg ${filePath} --config ${configPath}`)
const { stderr } = await execFile('npx', ['pkg', filePath, '--config', configPath], { shell: true })

// there should be no error when packaging
const expectedvalue = stderr === '' || deprecationWarningRegex.test(stderr)
@@ -42,7 +44,7 @@ test('worker test when packaged into executable using pkg', { skip: !!process.en
executablePath = `./${executablePath}`
}

const { stderr } = await exec(executablePath)
const { stderr } = await execFile(executablePath)

// check if there were no errors
const expectedvalue = stderr === '' || deprecationWarningRegex.test(stderr)
4 changes: 4 additions & 0 deletions test/types/pino.test-d.ts
Original file line number Diff line number Diff line change
@@ -209,6 +209,10 @@ const withHooks = pino({
expectType<pino.Logger>(this);
return method.apply(this, args);
},
streamWrite(s) {
expectType<string>(s);
return s.replaceAll('secret-key', 'xxx');
},
},
});