Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typings for logger getters #620

Merged
merged 2 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,15 @@ export interface LoggerEntryContent {
[key: string]: any
}

export type Logger = (entry: LogEntry) => void

export type logCreator = (logLevel: logLevel) => (entry: LogEntry) => void

export type Logger = {
info: (message: string, extra?: object) => void
error: (message: string, extra?: object) => void
warn: (message: string, extra?: object) => void
debug: (message: string, extra?: object) => void
}

export type Broker = {
isConnected(): boolean
connect(): Promise<void>
Expand Down
5 changes: 5 additions & 0 deletions types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ const kafka = new Kafka({
logCreator: (logLevel: logLevel) => (entry: LogEntry) => {},
})

kafka.logger().error('Instantiated KafkaJS')

// CONSUMER
const consumer = kafka.consumer({ groupId: 'test-group' })
consumer.logger().info('Instantiated logger', { groupId: 'test-group' })

let removeListener = consumer.on(consumer.events.HEARTBEAT, e =>
console.log(`heartbeat at ${e.timestamp}`)
Expand Down Expand Up @@ -100,6 +103,7 @@ runConsumer().catch(console.error)

// PRODUCER
const producer = kafka.producer({ allowAutoTopicCreation: true })
producer.logger().debug('Instantiated producer')

removeListener = producer.on(producer.events.CONNECT, e =>
console.log(`Producer connect at ${e.timestamp}`)
Expand Down Expand Up @@ -135,6 +139,7 @@ runProducer().catch(console.error)

// ADMIN
const admin = kafka.admin({ retry: { retries: 10 } })
admin.logger().warn('Instantiated admin')

removeListener = admin.on(admin.events.CONNECT, e => console.log(`Admin connect at ${e.timestamp}`))
removeListener()
Expand Down