Skip to content

Commit

Permalink
fix logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rbennettcw committed Feb 13, 2024
1 parent 661a298 commit 440c398
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 5 additions & 3 deletions libs/adapters/src/mixpanel/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Analytics, AnalyticsOptions } from '@hicommonwealth/core';
import { Analytics, AnalyticsOptions, logger } from '@hicommonwealth/core';
import MixpanelLib from 'mixpanel';

const log = logger().getLogger(__filename);

export const MixpanelAnalytics = (): Analytics => {
let mixpanelNode;

Expand All @@ -13,7 +15,7 @@ export const MixpanelAnalytics = (): Analytics => {
mixpanelNode = MixpanelLib.init(process.env.MIXPANEL_DEV_TOKEN);
}
} catch (e) {
console.error('Unable to initialized the backend mixpanel client: ', e);
log.error('Unable to initialized the backend mixpanel client: ', e);
}

return {
Expand All @@ -23,7 +25,7 @@ export const MixpanelAnalytics = (): Analytics => {
try {
mixpanelNode?.track(event, payload);
} catch (e) {
console.log(`Failed to track event, ${event.toString()}:`, e.message);
log.error(`Failed to track event, ${event.toString()}:`, e.message);
}
},
};
Expand Down
5 changes: 1 addition & 4 deletions libs/core/src/ports/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AnalyticsOptions } from '../types';
import { Analytics, Cache, Logger, Stats } from './interfaces';
import { port } from './port';

Expand Down Expand Up @@ -92,9 +91,7 @@ export const analytics = port(function analytics(analytics?: Analytics) {
analytics || {
name: 'in-memory-analytics',
dispose: () => Promise.resolve(),
track: (event: string, payload: AnalyticsOptions) => {
console.log(`TRACK [${event}]: ${JSON.stringify(payload)}`);
},
track: () => {},
}
);
});

2 comments on commit 440c398

@Rotorsoft
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just make sure this change doesn’t break the Typescript logger injection. Sometimes the order of imports causes the default logger to take precedence

@rbennettcw
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the logger call to the scope of the Mixpanel adapter function, so it should use whichever logger is set when the mixpanel adapter is loaded?

Please sign in to comment.