Skip to content

Commit

Permalink
Update to @hapi/hapi@20.2.1 and pino-pretty@4.0.0 (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaestrada committed Nov 5, 2021
1 parent 355af68 commit 204c96e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
78 changes: 78 additions & 0 deletions benchmarks/hapi-pino-with-pino-pretty.js
@@ -0,0 +1,78 @@
'use strict'
// see docs https://github.com/pinojs/pino/blob/master/docs/pretty.md *prod
// see docs https://github.com/pinojs/pino-pretty *dev
const Hapi = require('@hapi/hapi')
// manage logs
const Pino = require('..')
// const sonic = require('sonic-boom')
// const Path = require('path')
// const { join } = require('path')

const getResponse = [
{ string: 'string1', number: 1, boolean: true },
{ string: 'string2', number: 2, boolean: false }
]

async function start () {
// Create a server with a host and port
const server = Hapi.server({
host: 'localhost',
port: 3000,
debug: false // disable Hapi debug console logging
})

// Add the route
server.route({
method: 'GET',
path: '/items',
handler: async function (request, h) {
// test sonicBoob library works
// const sonic = new SonicBoom({
// dest: './pino-logs/node_trace.1.log',
// append: true,
// mkdir: true
// });
return h.response(getResponse)
}
})
// const tmpDir = Path.join(__dirname, '.tmp_' + Date.now())
// const destination = join(tmpDir, 'output')

await server.register({
plugin: Pino,
options: {
logPayload: true,
mergeHapiLogData: true,
ignorePaths: ['/alive.txt', '/private'],
ignoreFunc: (options, request) => request.path.startsWith('/private'),
transport: {
target: 'pino-pretty',
options: {
colorize: true,
minimumLevel: 'info',
levelFirst: true,
messageFormat: true,
timestampKey: 'time',
translateTime: true,
singleLine: true,
mkdir: true,
append: true // the next line is breaking the app
// destination: new sonic({
// dest: destination || 1,
// append: true,
// mkdir: true,
// sync: true
// })
}
}
}
})
await server.start()
server.log(['info'], `server running: ${server.info.uri}/items`)
return server
}

start().catch((err) => {
console.log(err)
process.exit(1)
})
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -20,7 +20,7 @@
"license": "MIT",
"devDependencies": {
"@hapi/code": "^8.0.0",
"@hapi/hapi": "^20.0.0",
"@hapi/hapi": "^20.2.1",
"@hapi/lab": "^24.3.2",
"coveralls": "^3.0.11",
"flush-write-stream": "^2.0.0",
Expand All @@ -34,7 +34,7 @@
"abstract-logging": "^2.0.0",
"get-caller-file": "^2.0.5",
"pino": "^7.0.0",
"pino-pretty": "^4.0.0"
"pino-pretty": "^7.2.0"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 204c96e

Please sign in to comment.