0

i am using azure functions written in nodejs.

I have this azure function

module.exports = async function (context, req) {
    const title = req.body.title;
    console.log('title', title);
    if (title) {
        req.body.completed = false;
        context.bindings.outputDocument = req.body;
        context.res = {
            body: { success: true, message: `Todo added successfully` }
        };
    } else {
        context.res = {
            status: 400,
            body: { success: false, message: `Please add title field` }
        };
    }
};

and the binding

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "cosmosDB",
      "name": "outputDocument",
      "databaseName": "xxx",
      "collectionName": "items",
      "createIfNotExists": false,
      "connectionStringSetting": "xxx",
      "partitionKey": "/all",
      "direction": "out"
    }
  ],
  "disabled": false
}

locally when i run

func host start

i don't see my console log statement.

How can i see on localhost ?

And where i need to go in my azure portal to see the logs there after deployment.

I tried to go in Function App - open my function and there the azure function but i can't see any logs there...

sdsd
  • 447
  • 3
  • 20

2 Answers2

1

This should probably resolve your issue.

Azure Functions JavaScript developer guide:

Don't use console.log to write trace outputs. Because output from console.log is captured at the function app level, it's not tied to a specific function invocation and isn't displayed in a specific function's logs.

Max Ivanov
  • 5,695
  • 38
  • 52
1

How can i see on localhost ?

And where i need to go in my azure portal to see the logs there after deployment.

I tried to go in Function App - open my function and there the azure function but i can't see any logs there...

Of course, you can get the log files on local. I assume you are based on windows, then just edit the host.json like this:

{
  "version": "2.0",
  "logging": {
    "fileLoggingMode": "always",
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  }
}

And go to

C:\Users\yourusernameonlocal\AppData\Local\Temp\LogFiles\Application\Functions\Function\yourfunctionname

After that you will see the log files.:)

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27