From 00c5f9f7d6f1aeaae33e4745a835900af4b0e888 Mon Sep 17 00:00:00 2001 From: aaestrada Date: Fri, 5 Nov 2021 13:24:01 -0700 Subject: [PATCH] Update to @hapi/hapi@20.2.1 and pino-pretty@4.0.0 --- benchmarks/hapi-pino-with-pino-pretty.js | 78 ++++++++++++++++++++++++ package.json | 4 +- 2 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 benchmarks/hapi-pino-with-pino-pretty.js diff --git a/benchmarks/hapi-pino-with-pino-pretty.js b/benchmarks/hapi-pino-with-pino-pretty.js new file mode 100644 index 0000000..59e8d19 --- /dev/null +++ b/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) +}) diff --git a/package.json b/package.json index 7eea92d..b783dd1 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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",