bragma / winston-azure-application-insights

Azure Application Insights transport for Winston
MIT License
16 stars 25 forks source link

this.client is undefined #15

Closed joostpielage closed 6 years ago

joostpielage commented 6 years ago

Hi @bragma ,

I would love top your app but I cannot get it right. This is the code I am having:

const aiLogger = require('winston-azure-application-insights').AzureApplicationInsightsLogger; const appInsights = require("applicationinsights"); appInsights.setup("64352017-d16d-49f4-9f61-a9b1188ef47f").start(); let client = appInsights.defaultClient; let result = aiLogger({client : client});

Right now I seem to keep having this error:

TypeError: Cannot set property 'client' of undefined winston-azure-application-insights.js:61 at AzureApplicationInsightsLogger

Any idea what is going wrong?

willmorgan commented 6 years ago

This is not a library defect; you are instantiating winston-azure-application-insights in an unusual way.

If you wish to keep the code as-is, you are missing the new when creating result:

const result = new aiLogger({ client });

Otherwise please see the docs.

joostpielage commented 6 years ago

Thank you it is working now. Javascript.... Thank you for helping me out.