Created
March 12, 2024 16:13
-
-
Save midnightcodr/afef5484e971ced42b10ce822d8ff251 to your computer and use it in GitHub Desktop.
hapijs + pino + kafka
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pino = require('pino') | |
const pkafka = require('pino-kafka') | |
// this can be from .env, via JSON.parse | |
const kafkaLogConfig = { | |
"clientId":"some-producer1", | |
"defaultTopic": "some-log-topic", | |
"brokers":["some-host:9092"] | |
} | |
const streams = [{ stream: process.stdout, level: 'info' }] | |
if (kafkaLogConfig) { | |
streams.push({ stream: pkafka(kafkaLogConfig) }) | |
} | |
const logger = pino( | |
{ | |
redact: [ | |
'req.headers.api-key', | |
] | |
}, | |
pino.multistream(streams) | |
) | |
// ... | |
server.register([{ | |
plugin: require('hapi-pino'), | |
options: { | |
instance: logger | |
} | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment