mixpanel / mixpanel-node

A node.js API for mixpanel
http://www.mixpanel.com
MIT License
477 stars 159 forks source link

Custom logger support #222

Closed iatsiuk closed 1 year ago

iatsiuk commented 1 year ago

Hi,

This PR is from a discussion in this issue.

It adds support to pass a custom logger to the mixpanel instance. The custom logger should implement the following interface:

interface CustomLogger {
  trace(message?: any, ...optionalParams: any[]): void;
  debug(message?: any, ...optionalParams: any[]): void;
  info(message?: any, ...optionalParams: any[]): void;
  warn(message?: any, ...optionalParams: any[]): void;
  error(message?: any, ...optionalParams: any[]): void;
}

Here is an example output for the console logger, which will be used by default if no logger is passed:

Sending the following data to Mixpanel (/engage) {
  data: {
    '$token': 'TOKEN',
    '$distinct_id': 'ID',
    '$set': {
      foo: 'bar'
    }
  }
}

Here is an example output for the pinojs logger:

[1692475025041] DEBUG (API/10184 on Nicolle.local): Sending the following data to Mixpanel (/engage) {"data":{"$token":"TOKEN","$distinct_id":"ID","foo":"bar"}}}
iatsiuk commented 1 year ago

Thanks for your kind words. I will fix all the problems later in the week.

iatsiuk commented 1 year ago

@tdumitrescu I have made the necessary corrections and addressed all the issues you raised. Please let me know if there is anything else I can do to improve the code or if you have any further suggestions.

tdumitrescu commented 1 year ago

Thanks @iatsiuk. This has now been released in v0.18.0.