nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pinojs/pino-pretty
Pull request #513 (2024-05-23 06:59:05)

feat: Added exports color support in TTY
- Exporting `isColorSupported` from `Colorette` to check for color support without installing the dependency again.
- Also required in this PR https://github.com/fastify/one-line-logger/pull/42


Patch:
diff --git a/Readme.md b/Readme.md
index 8fd48ba..5004029 100644
--- a/Readme.md
+++ b/Readme.md
@@ -230,6 +230,19 @@ module.exports = opts => require('pino-pretty')({
 })
 ```
 
+### Checking color support in TTY
+
+This boolean returns whether the currently used TTY supports colorizing the logs.
+
+```js
+import pretty from 'pino-pretty'
+
+if (pretty.isColorSupported) {
+  ...
+}
+
+```
+
 <a id="options"></a>
 ### Options
 
diff --git a/index.d.ts b/index.d.ts
index 72b2a6b..eecdbf2 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -213,6 +213,7 @@ interface PrettyOptions_ {
 }
 
 declare function build(options: PrettyOptions_): PinoPretty.PrettyStream;
+type isColorSupported = PinoPretty.isColorSupported
 
 declare namespace PinoPretty {
   type Prettifier<T = object> = (inputData: string | object, key: string, log: object, extras: PrettifierExtras<T>) => string;
@@ -224,7 +225,8 @@ declare namespace PinoPretty {
   type ColorizerFactory = typeof colorizerFactory;
   type PrettyFactory = typeof prettyFactory;
   type Build = typeof build;
+  type isColorSupported = typeof Colorette.isColorSupported;
 }
 
 export default PinoPretty;
-export { build, PinoPretty, PrettyOptions_ as PrettyOptions, colorizerFactory, prettyFactory };
+export { build, PinoPretty, PrettyOptions_ as PrettyOptions, colorizerFactory, prettyFactory, isColorSupported };
diff --git a/index.js b/index.js
index 66a0afd..31d8fa8 100644
--- a/index.js
+++ b/index.js
@@ -178,4 +178,5 @@ module.exports = build
 module.exports.build = build
 module.exports.prettyFactory = prettyFactory
 module.exports.colorizerFactory = colors
+module.exports.isColorSupported = isColorSupported
 module.exports.default = build


Test patch:
diff --git a/test/basic.test.js b/test/basic.test.js
index 18f74c1..ede3f70 100644
--- a/test/basic.test.js
+++ b/test/basic.test.js
@@ -1179,6 +1179,12 @@ test('basic prettifier tests', (t) => {
     log.info('foo')
   })
 
+  t.test('check support for colors', (t) => {
+    t.plan(1)
+    const isColorSupported = pinoPretty.isColorSupported
+    t.type(isColorSupported, 'boolean')
+  })
+
   t.end()
 })
Repository: pinojs/hapi-pino
Pull request #14 (2017-04-06 16:10:43)

Fix bad encoding
Hey,

I was testing my apply with hapi 16.1.1,  specifically, the way it handles invalid accept-encoding error since accept-encoding.

Looks like this is not working, because, when hapi is checking the error, it does `request.log`.
But at this point, the logger is not yet attached to the request, that is why it fails.

```
TypeError: Cannot read property 'error' of undefined
    at logEvent (PROJECT/node_modules/hapi-pino/index.js:106:16)
    at PROJECT/node_modules/hapi-pino/index.js:64:5
    at invoke (PROJECT/node_modules/hapi/node_modules/podium/lib/index.js:239:30)
    at each (PROJECT/node_modules/hapi/node_modules/podium/lib/index.js:243:13)
    at Object.exports.parallel (PROJECT/node_modules/hapi/node_modules/items/lib/index.js:70:13)
    at Object.internals.emit (PROJECT/node_modules/hapi/node_modules/podium/lib/index.js:260:18)
    at internals.Podium._emit (PROJECT/node_modules/hapi/node_modules/podium/lib/index.js:140:15)
    at each (PROJECT/node_modules/hapi/node_modules/podium/lib/index.js:181:47)
    at Object.exports.parallel (PROJECT/node_modules/hapi/node_modules/items/lib/index.js:70:13)
    at relay (PROJECT/node_modules/hapi/node_modules/podium/lib/index.js:182:15)```

This PR fix the problem.
I made a test to show the problem. It probably can be improved, at least shows that it does nto crash any more with my fix.


Patch:
diff --git a/index.js b/index.js
index 31336c3..1c74140 100644
--- a/index.js
+++ b/index.js
@@ -59,6 +59,7 @@ function register (server, options, next) {
   })
 
   server.on('request', function (request, event) {
+    request.logger = request.logger || logger.child({ req: request })
     logEvent(request.logger, event)
   })
 


Test patch:
diff --git a/test.js b/test.js
index 5975785..60e5d41 100644
--- a/test.js
+++ b/test.js
@@ -182,6 +182,25 @@ experiment('logs each request', () => {
     })
   })
 
+  test('handles bad encoding', (done) => {
+    const server = getServer()
+    server.route({
+      path: '/',
+      method: 'GET',
+      handler: (req, reply) => reply('')
+    })
+    registerWithSink(server, 'info', (data, enc) => {
+      expect(data.data.header).equal('a;b')
+      done()
+    }, (err) => {
+      expect(err).to.be.undefined()
+      server.inject({
+        url: '/',
+        headers: { 'accept-encoding': 'a;b' }
+      })
+    })
+  })
+
   test('set the request logger', (done) => {
     const server = getServer()
     let count = 0
Repository: pinojs/hapi-pino
Pull request #38 (2017-12-06 12:34:00)

Use higher tag level


Patch:
diff --git a/index.js b/index.js
index 1d76f4b..d5b292f 100644
--- a/index.js
+++ b/index.js
@@ -46,10 +46,15 @@ async function register (server, options) {
   const allTags = options.allTags || 'info'
 
   const validTags = Object.keys(tagToLevels).filter((key) => levels.indexOf(tagToLevels[key]) < 0).length === 0
-  if (!validTags || (allTags && levels.indexOf(allTags) < 0)) {
+  if (!validTags || levels.indexOf(allTags) < 0) {
     throw new Error('invalid tag levels')
   }
 
+  const tagToLevelValue = {}
+  for (let tag in tagToLevels) {
+    tagToLevelValue[tag] = logger.levels.values[tagToLevels[tag]]
+  }
+
   var ignoreTable = {}
   if (options.ignorePaths) {
     for (let i = 0; i < options.ignorePaths.length; i++) {
@@ -132,8 +137,6 @@ async function register (server, options) {
   function logEvent (current, event) {
     var tags = event.tags
     var data = event.data
-    var level
-    var found = false
 
     var logObject
     if (mergeHapiLogData) {
@@ -146,16 +149,18 @@ async function register (server, options) {
       logObject = { tags, data }
     }
 
-    for (var i = 0; i < tags.length; i++) {
-      level = tagToLevels[tags[i]]
-      if (level) {
-        current[level](logObject)
-        found = true
-        break
+    let highest = 0
+
+    for (let tag of tags) {
+      const level = tagToLevelValue[tag]
+      if (level && level > highest) {
+        highest = level
       }
     }
 
-    if (!found && allTags) {
+    if (highest > 0) {
+      current[current.levels.labels[highest]](logObject)
+    } else {
       current[allTags](logObject)
     }
   }


Test patch:
diff --git a/test.js b/test.js
index 422af45..b752071 100644
--- a/test.js
+++ b/test.js
@@ -323,8 +323,8 @@ experiment('logs through server.log', () => {
       bbb: 'warn'
     }, (data) => {
       expect(data.data).to.equal('hello world')
-      // first matching tag
-      expect(data.level).to.equal(30)
+      // highest level tag
+      expect(data.level).to.equal(40)
       resolver()
     })
Repository: pinojs/hapi-pino
Pull request #40 (2017-12-20 12:17:01)

log error with server.log
Add the handling of errors logged with `server.log()` — those get ignored up to now.
Adjust the behavior to `request.log()`


Patch:
diff --git a/index.js b/index.js
index 4ce5fbc..b67e829 100644
--- a/index.js
+++ b/index.js
@@ -78,7 +78,11 @@ async function register (server, options) {
   })
 
   server.events.on('log', function (event) {
-    logEvent(logger, event)
+    if (event.error) {
+      logger.warn({ err: event.error })
+    } else {
+      logEvent(logger, event)
+    }
   })
 
   // log via `request.log()` and optionally when an internal `accept-encoding`


Test patch:
diff --git a/test.js b/test.js
index a2f29af..ad99fc5 100644
--- a/test.js
+++ b/test.js
@@ -314,6 +314,26 @@ experiment('logs through server.log', () => {
     await done
   })
 
+  test('with logged error object', async () => {
+    const server = getServer()
+    let resolver
+    const done = new Promise((resolve, reject) => {
+      resolver = resolve
+    })
+
+    await tagsWithSink(server, {}, (data) => {
+      expect(data.err.type).to.equal('Error')
+      expect(data.err.message).to.equal('foobar')
+      expect(data.err.stack).to.exist()
+      // highest level tag
+      expect(data.level).to.equal(40)
+      resolver()
+    })
+
+    server.log(['error'], new Error('foobar'))
+    await done
+  })
+
   test('one log for multiple tags', async () => {
     const server = getServer()
     let resolver
Repository: pinojs/hapi-pino
Pull request #72 (2019-02-08 23:11:54)

update ignorePaths logic
According to the hapi 18 release notes, `request.url.path` has gone away in favor of `request.path` or `request.url.pathname`. The same release notes also state that `request.url.pathname` has not changed.

Refs: https://github.com/hapijs/hapi/issues/3871

coveralls: 
[![Coverage Status](https://coveralls.io/builds/21542097/badge)](https://coveralls.io/builds/21542097)

Coverage increased (+0.003%) to 98.81% when pulling **266c3e23c7afaea9afb02845acd7a9469d848612 on cjihrig:ignores** into **11a62356d9c4cb81a73bc65073469384c859d8a1 on pinojs:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/21542097/badge)](https://coveralls.io/builds/21542097)

Coverage increased (+0.003%) to 98.81% when pulling **266c3e23c7afaea9afb02845acd7a9469d848612 on cjihrig:ignores** into **11a62356d9c4cb81a73bc65073469384c859d8a1 on pinojs:master**.

mcollina: @cjihrig tests are failing with Hapi@17: https://travis-ci.org/pinojs/hapi-pino/jobs/490787436.
cjihrig: @mcollina pushed up something that should fix it

Patch:
diff --git a/index.js b/index.js
index 3705fb8..8dfc750 100644
--- a/index.js
+++ b/index.js
@@ -70,7 +70,7 @@ async function register (server, options) {
 
   // set a logger for each request
   server.ext('onRequest', (request, h) => {
-    if (options.ignorePaths && ignoreTable[request.url.path]) {
+    if (options.ignorePaths && ignoreTable[request.url.pathname]) {
       request.logger = nullLogger
       return h.continue
     }
@@ -106,7 +106,7 @@ async function register (server, options) {
 
   // log when a request completes
   tryAddEvent(server, options, 'on', 'response', function (request) {
-    if (options.ignorePaths && ignoreTable[request.url.path]) {
+    if (options.ignorePaths && ignoreTable[request.url.pathname]) {
       return
     }
 


Test patch:
diff --git a/test.js b/test.js
index 1817904..745d9d5 100644
--- a/test.js
+++ b/test.js
@@ -1001,7 +1001,7 @@ experiment('ignore request logs for paths in ignorePaths', () => {
       resolver = resolve
     })
     const stream = sink((data) => {
-      expect(data.req.url).to.not.equal('/ignored')
+      expect(data.req.url).to.endWith('/foo')
       resolver()
     })
     const logger = require('pino')(stream)
@@ -1022,7 +1022,7 @@ experiment('ignore request logs for paths in ignorePaths', () => {
 
     await server.inject({
       method: 'PUT',
-      url: '/'
+      url: '/foo'
 
     })
     await done
@@ -1037,8 +1037,8 @@ experiment('ignore response logs for paths in ignorePaths', () => {
       resolver = resolve
     })
     const stream = sink((data) => {
+      expect(data.req.url).to.endWith('/foo')
       expect(data.msg).to.equal('request completed')
-      expect(data.req.url).to.not.equal('/ignored')
       resolver()
     })
     const logger = require('pino')(stream)
@@ -1060,7 +1060,7 @@ experiment('ignore response logs for paths in ignorePaths', () => {
 
     await server.inject({
       method: 'PUT',
-      url: '/'
+      url: '/foo'
 
     })
     await done
Repository: pinojs/hapi-pino
Pull request #122 (2020-09-02 05:30:27)

Added logQueryParams option to log the query params

coveralls: 
[![Coverage Status](https://coveralls.io/builds/33167257/badge)](https://coveralls.io/builds/33167257)

Coverage increased (+0.01%) to 99.073% when pulling **32ee9c2a67dee86a3c25ebe7e4c5ae3a679cff56 on adarshkr:master** into **b0eab69e2f662c3eec55bdb9be58b5f9026c36ce on pinojs:master**.


Patch:
diff --git a/README.md b/README.md
index 18de622..3f13f16 100644
--- a/README.md
+++ b/README.md
@@ -93,6 +93,11 @@ events"](#hapievents) section.
 
   When enabled, add the request payload as `payload` to the `response` event log.
 
+### `options.logQueryParams: boolean`
+
+  **Default**: `false`
+
+  When enabled, add the request query as `queryParams` to the `response` event log.
 
 ### `options.logRouteTags: boolean`
 
diff --git a/index.js b/index.js
index 60a722c..34b3ad3 100644
--- a/index.js
+++ b/index.js
@@ -160,6 +160,7 @@ async function register (server, options) {
       request.logger.info(
         {
           payload: options.logPayload ? request.payload : undefined,
+          queryParams: options.logQueryParams ? request.query : undefined,
           tags: options.logRouteTags ? request.route.settings.tags : undefined,
           // note: pino doesnt support unsetting a key, so this next line
           // has the effect of setting it or "leaving it as it was" if it was already added via child bindings


Test patch:
diff --git a/test.js b/test.js
index 57e07d2..a4a81b2 100644
--- a/test.js
+++ b/test.js
@@ -2064,3 +2064,34 @@ experiment('ignore the log event triggered by request.log and server.log', () =>
     expect(called).to.be.false()
   })
 })
+
+experiment('logging with request queryParams', () => {
+  test('with pre-defined req serializer', async () => {
+    const server = getServer()
+    let resolver
+    const done = new Promise((resolve, reject) => {
+      resolver = resolve
+    })
+    const stream = sink(data => {
+      expect(data.queryParams).to.equal({ foo: '42', bar: '43' })
+      resolver()
+    })
+    const logger = require('pino')(stream)
+    const plugin = {
+      plugin: Pino,
+      options: {
+        instance: logger,
+        logQueryParams: true
+      }
+    }
+
+    await server.register(plugin)
+
+    await server.inject({
+      method: 'POST',
+      url: '/?foo=42&bar=43'
+    })
+
+    await done
+  })
+})
Repository: pinojs/hapi-pino
Pull request #138 (2021-06-01 17:21:39)

Respect `messageKey` option when `mergeHapiLogData` is set
See https://github.com/pinojs/pino/blob/master/docs/api.md#messagekey-string


Patch:
diff --git a/index.js b/index.js
index 34b3ad3..851af33 100644
--- a/index.js
+++ b/index.js
@@ -76,6 +76,7 @@ async function register (server, options) {
   }
 
   const mergeHapiLogData = options.mergeHapiLogData
+  const messageKey = options.messageKey || 'msg'
   const getChildBindings = options.getChildBindings ? options.getChildBindings : (request) => ({ req: request })
   const shouldLogRequestStart = typeof options.logRequestStart === 'function'
     ? (request) => options.logRequestStart(request)
@@ -244,7 +245,7 @@ async function register (server, options) {
     var logObject
     if (mergeHapiLogData) {
       if (typeof data === 'string') {
-        data = { msg: data }
+        data = { [messageKey]: data }
       }
 
       logObject = Object.assign({ tags }, data)


Test patch:
diff --git a/test.js b/test.js
index 3653883..c842095 100644
--- a/test.js
+++ b/test.js
@@ -1275,6 +1275,31 @@ experiment('logging with mergeHapiLogData option enabled', () => {
     server.log(['info'], 'hello world')
     await finish
   })
+
+  test('respects `messageKey` option', async () => {
+    const server = getServer()
+    let done
+    const finish = new Promise(function (resolve, reject) {
+      done = resolve
+    })
+    const stream = sink(data => {
+      expect(data).to.include({ message: 'hello world' })
+      done()
+    })
+    const plugin = {
+      plugin: Pino,
+      options: {
+        stream: stream,
+        level: 'info',
+        mergeHapiLogData: true,
+        messageKey: 'message'
+      }
+    }
+
+    await server.register(plugin)
+    server.log(['info'], 'hello world')
+    await finish
+  })
 })
 
 experiment('custom serializers', () => {
Repository: pinojs/hapi-pino
Pull request #153 (2022-01-31 17:16:40)

Include tags when errors are logged with server.log()

coveralls: 
[![Coverage Status](https://coveralls.io/builds/46093567/badge)](https://coveralls.io/builds/46093567)

Coverage increased (+0.0004%) to 98.991% when pulling **52374d5abcccb7ecc87cbc2da5380f8912e98dc0 on jonathansamines:feature/server-log-tags** into **d45fcefd66c6fe1b9c2fc390f4e2f2e0109bcc2b on pinojs:master**.


Patch:
diff --git a/index.js b/index.js
index e811cc7..6d011d7 100644
--- a/index.js
+++ b/index.js
@@ -119,7 +119,7 @@ async function register (server, options) {
   server.events.on('log', function (event) {
     if (!isCustomTagsLoggingIgnored(event, ignoredEventTags.log)) { // first check on ignoring tags
       if (event.error) {
-        logger.error({ err: event.error })
+        logger.error({ err: event.error, tags: event.tags })
       } else {
         logEvent(logger, event)
       }


Test patch:
diff --git a/test.js b/test.js
index b0848e2..aa3d5f0 100644
--- a/test.js
+++ b/test.js
@@ -426,6 +426,7 @@ experiment('logs through server.log', () => {
     })
 
     await tagsWithSink(server, {}, data => {
+      expect(data.tags).to.equal(['error', 'tag'])
       expect(data.err.type).to.equal('Error')
       expect(data.err.message).to.equal('foobar')
       expect(data.err.stack).to.exist()
@@ -434,7 +435,7 @@ experiment('logs through server.log', () => {
       resolver()
     })
 
-    server.log(['error'], new Error('foobar'))
+    server.log(['error', 'tag'], new Error('foobar'))
     await done
   })
Repository: pinojs/hapi-pino
Pull request #154 (2022-03-09 20:14:08)

fix: allow logging numbers when mergeHapiLogData is true
The number/data from the log was being erased by the `Object.assign`.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/47231832/badge)](https://coveralls.io/builds/47231832)

Coverage increased (+0.01%) to 99.0% when pulling **6f6a9ea7516fbd87b9b41c2a8878f8794cb07c3a on AdriVanHoudt:master** into **7907e21c68619b14bffbe549cc80f23f593829b2 on pinojs:master**.


Patch:
diff --git a/index.js b/index.js
index 6d011d7..a9cb1af 100644
--- a/index.js
+++ b/index.js
@@ -252,7 +252,7 @@ async function register (server, options) {
 
     var logObject
     if (mergeHapiLogData) {
-      if (typeof data === 'string') {
+      if (typeof data === 'string' || typeof data === 'number') {
         data = { [messageKey]: data }
       }
 


Test patch:
diff --git a/test.js b/test.js
index aa3d5f0..8087a9b 100644
--- a/test.js
+++ b/test.js
@@ -1336,6 +1336,30 @@ experiment('logging with mergeHapiLogData option enabled', () => {
     await finish
   })
 
+  test('when data is a number, merge it as msg property', async () => {
+    const server = getServer()
+    let done
+    const finish = new Promise(function (resolve, reject) {
+      done = resolve
+    })
+    const stream = sink(data => {
+      expect(data).to.include({ msg: 1 })
+      done()
+    })
+    const plugin = {
+      plugin: Pino,
+      options: {
+        stream: stream,
+        level: 'info',
+        mergeHapiLogData: true
+      }
+    }
+
+    await server.register(plugin)
+    server.log(['info'], 1)
+    await finish
+  })
+
   test('respects `messageKey` option', async () => {
     const server = getServer()
     let done
Repository: pinojs/pino
Pull request #155 (2016-12-30 15:02:22)

Fix prettifier crashing when receiving the line: `null`
Issue #154 shows that if the prettifier receives a line value that is the literal text `null\n`, then `isPinoLine` will fail. The issue is that the spec (https://tools.ietf.org/html/rfc7159#section-3) allows literal values `null`, `true`, and `false` as valid JSON in addition to `[]` and `{}`. But `null` is not an object, so it doesn't have the `hasOwnProperty` method; thus the crash.


Patch:
diff --git a/pretty.js b/pretty.js
index 24ccb00..844021f 100755
--- a/pretty.js
+++ b/pretty.js
@@ -47,7 +47,10 @@ function filter (value) {
 }
 
 function isPinoLine (line) {
-  return line.hasOwnProperty('hostname') && line.hasOwnProperty('pid') && (line.hasOwnProperty('v') && line.v === 1)
+  return line &&
+    line.hasOwnProperty('hostname') &&
+    line.hasOwnProperty('pid') &&
+    (line.hasOwnProperty('v') && line.v === 1)
 }
 
 function pretty (opts) {


Test patch:
diff --git a/test/pretty.test.js b/test/pretty.test.js
index ab9a747..fb89080 100644
--- a/test/pretty.test.js
+++ b/test/pretty.test.js
@@ -139,3 +139,36 @@ test('pino transform treats the name with care', function (t) {
 
   instance.info('hello world')
 })
+
+test('handles `null` input', function (t) {
+  t.plan(1)
+  var pretty = pino.pretty()
+  pretty.pipe(split(function (line) {
+    t.is(line, 'null')
+    return line
+  }))
+  pretty.write('null')
+  pretty.end()
+})
+
+test('handles `undefined` input', function (t) {
+  t.plan(1)
+  var pretty = pino.pretty()
+  pretty.pipe(split(function (line) {
+    t.is(line, 'undefined')
+    return line
+  }))
+  pretty.write('undefined')
+  pretty.end()
+})
+
+test('handles `true` input', function (t) {
+  t.plan(1)
+  var pretty = pino.pretty()
+  pretty.pipe(split(function (line) {
+    t.is(line, 'true')
+    return line
+  }))
+  pretty.write('true')
+  pretty.end()
+})
Repository: pinojs/pino
Pull request #173 (2017-01-16 21:00:01)

Pretty accepts custom logLevel
fix for #172 



Patch:
diff --git a/pretty.js b/pretty.js
index 844021f..ab661d7 100755
--- a/pretty.js
+++ b/pretty.js
@@ -7,6 +7,7 @@ var Parse = require('fast-json-parse')
 var chalk = require('chalk')
 
 var levels = {
+  default: 'USERLVL',
   60: 'FATAL',
   50: 'ERROR',
   40: 'WARN',
@@ -70,6 +71,7 @@ function pretty (opts) {
     })
 
     levelColors = {
+      default: ctx.white,
       60: ctx.bgRed,
       50: ctx.red,
       40: ctx.yellow,
@@ -128,7 +130,11 @@ function pretty (opts) {
   }
 
   function asColoredLevel (value) {
-    return levelColors[value.level](levels[value.level])
+    if (levelColors.hasOwnProperty(value.level)) {
+      return levelColors[value.level](levels[value.level])
+    } else {
+      return levelColors.default(levels.default)
+    }
   }
 }
 


Test patch:
diff --git a/test/pretty.test.js b/test/pretty.test.js
index fb89080..73e49de 100644
--- a/test/pretty.test.js
+++ b/test/pretty.test.js
@@ -172,3 +172,17 @@ test('handles `true` input', function (t) {
   pretty.write('true')
   pretty.end()
 })
+
+test('accept customLogLevvel', function (t) {
+  t.plan(1)
+  var pretty = pino.pretty()
+
+  pretty.pipe(split(function (line) {
+    t.ok(line.indexOf('USERLVL') > 0, 'include custom level')
+    return line
+  }))
+
+  var instance = pino({level: 'testCustom', levelVal: 35}, pretty)
+
+  instance.testCustom('test message')
+})