BrianRosamilia / azure-function-log-intercept

Add console.log support to Azure Functions
27 stars 2 forks source link

Exception: TypeError: context[name] is not a function #1

Closed tsart closed 4 years ago

tsart commented 4 years ago

Running console.info/warn/error methods throw an exception

Exception: TypeError: context[name] is not a function
Stack: TypeError: context[name] is not a function
    at Object.logFn [as info] (D:\home\site\wwwroot\node_modules\azure-function-log-intercept\index.js:11:22)

This code should be replaced

    const logFn = (...params) => {
        savedMethod(...params);
        context[name](...params);
    };

with something like this

    const logFn = (...params) => {
        savedMethod(...params);
        ['info','warn','error'].includes(name) ? context.log[name](...params): context[name](...params);
    };

as these methods belong to the log object in function context.

BrianRosamilia commented 4 years ago

Wow you're right cant believe I missed this. I thought I checked this in the emulator before setting up my tests. I'll get this fixed today. Thank you @tsart 💯

Just for my own reference here's some docs on this https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node#writing-trace-output-to-the-console

BrianRosamilia commented 4 years ago

This should be fixed. Install 1.0.6 please! @tsart

Thanks again! (And this gave me a chance to try the Azurite emulator since my free cloud credits expired..)