Skip to content

Instantly share code, notes, and snippets.

@midnightcodr
Created March 12, 2024 16:13
Show Gist options
  • Save midnightcodr/afef5484e971ced42b10ce822d8ff251 to your computer and use it in GitHub Desktop.
Save midnightcodr/afef5484e971ced42b10ce822d8ff251 to your computer and use it in GitHub Desktop.
hapijs + pino + kafka
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