pinojs / pino-clf

🌲 Transport which transforms Pino HTTP logs into Common Log Format
MIT License
5 stars 0 forks source link

piping the output from HAPIv17 hapi-pino into pino-clf returns an error. #1

Open ghost opened 5 years ago

ghost commented 5 years ago

this is the error:

 [...]catalyst-core-ssr-app/node_modules/pino-toke/tokens.js:59
     return o.res.header.substr(0, 8).split('/')[1]
                        ^

 TypeError: Cannot read property 'substr' of undefined
    at Object.http-version ([...]catalyst-core-ssr-app/node_modules/pino-toke/tokens.js:59:25)

in may npm scripts, I am basically doing this: NODE_ENV=development node-dev --inspect --no-deps --respawn ./index.js | pino-clf

and registering the hapi-pino with no options.

mcollina commented 5 years ago

Can you send a full example to reproduce thia?

this module is also out of date. Would you like to send a PR to update the dependencies?

ghost commented 5 years ago

sorry for delay... example server:

const Hapi = require('hapi')

const server = Hapi.server({
  host: 'localhost',
  port: 8000
})

server.route({
  method: 'GET',
  path: '/hello',
  handler: function (request, h) {
    return 'hello world'
  }
})

const start = async function () {
  try {
    await server.register({
      plugin: require('hapi-pino')
    })
    await server.start()
  } catch (err) {
    console.log(err)
    process.exit(1)
  }

  server.log(['server', 'start'], `Server running at: ${server.info.uri}`)
}

start()

from the package.json

  "dependencies": {
    "hapi": "^18.1.0",
    "hapi-pino": "^5.4.1",
    "pino-clf": "^1.0.6"
  }

and the error:


/Users/example/node_modules/pino-toke/tokens.js:58
    return o.res.header.substr(0, 8).split('/')[1]
                        ^

TypeError: Cannot read property 'substr' of undefined
    at Object.http-version (/Users/example/node_modules/pino-toke/tokens.js:58:25)
    at eval (eval at compile (/Users/example/node_modules/pino-toke/index.js:37:10), <anonymous>:3:244)
    at DestroyableTransform._transform (/Users/example/node_modules/pino-toke/index.js:26:14)
    at DestroyableTransform.Transform._read (/Users/example/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/Users/example/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (/Users/example/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/Users/example/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at DestroyableTransform.Writable.write (/Users/example/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at DestroyableTransform.ondata (/Users/example/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:619:20)
    at emitOne (events.js:116:13)
mcollina commented 5 years ago

Ouch! Would you like to send a PR to fix this? This seems an incompatibility with hapi v17 in https://github.com/pinojs/pino-toke/blob/master/tokens.js.

samuelbsource commented 1 day ago

Honestly, this package seems severely outdated, it does not even work with express 4.