ancashoria / graphql-kafka-subscriptions

Apollo graphql subscriptions over Kafka protocol
MIT License
187 stars 55 forks source link

Logger expects bunyan #39

Open cramhead opened 4 years ago

cramhead commented 4 years ago

Thanks for making this package. I think it's really great.

I notice that logger method used are only debug, warn, info, and error, but when I pass my logger that supports those function I get the following.

error TS2345: Argument of type 'MyLogger' is not assignable to parameter of type 'Logger'.
  Type 'IsamLogger' is missing the following properties from type 'Logger': addStream, addSerializers, child, reopenFileStreams, and 21 more.

It's problematic to support all the interfaces that bunyan offers.

nick4fake commented 3 years ago

Temporary solution:

class LogBunyan {
  constructor(
    private logger: Logger,
  ) {
  }

  child() {
    return ({
      log: (...args: any[]) => this.logger.log(args.join(', ')),
      debug: (...args: any[]) => this.logger.debug(args.join(', ')),
      error: (...args: any[]) => this.logger.error(args.join(', ')),
      warn: (...args: any[]) => this.logger.warn(args.join(', ')),
      info: (...args: any[]) => this.logger.log(args.join(', ')),
    });
  }
}
new KafkaPubSub({
  topic,
  host,
  port,
  groupId,
  logger: new LogBunyan(logger) as unknown as BunyanLogger,
  globalConfig: {},
});
psugasti commented 3 years ago

how can I use my own log into graphql-kafka-subscriptions ?