Function logs are inconsistent in the Netlify Dashboard

I’ve run into this in the past before, but haven’t thought much of it.

Basically I have a JS function with several console.log() statements, but only some of them show up in the Function logs on the Netlify dashboard.

It really makes things difficult to debug.

I’ve also had it where the dashboard will only display part of the message, so instead of “Hello, World” it might say “ll, World”.

Is there a reason for this behavior? I haven’t been able to reproduce it consistently, sometimes I get all the logs and sometimes I don’t.

Hi @teakwood, are those event-triggered functions that are named after the event that triggers them? Do the functions that don’t log otherwise work for you?

@futuregerald no they are not event-triggered functions, and yes the functions that don’t log otherwise work. But it’s not a binary do/don’t log. It’s more like, some of the log statements won’t show up in the netlify log dashboard (but when I run them locally all of the log statements are there). I’ve also seen it where part of the log statement will be cut off, eg: “ello, world” vs “hello, world”, but then other logs are complete.

hi Teakwood, this is odd! do you have a screenshot of this? Any kind of pattern you are noticing at all?

I’ll snag a screenshot next time I run into it. I don’t have one on hand, but I’ve seen this behavior several times over the past ~5 months of using Netlify functions.

If a function call fails because there’s an error in the code, will the netlify logs still capture everything that was logged out before the failure?

@perry I’ve been having a lot of function based issues. I’m trying to test an event invoked function (submission-created.js) and the behavior is all over the place - some related to the issue here, and some not.

First off, you can see from my function logs the way the logs are cut off randomly in the middle of words. Second, you can see that the last invocation is logging “EVENT BODY” and then “undefined”. Those logs are from several deploys back, but were still logging after changing the lamda function and deploying with a cache clear. Now, as you can see from the deploy log screenshot, I’ve deployed since the last function invocation and I’ve attempted to invoke it again by the same means (submitting a contact form). Now, the function isn’t logging anything at all, event though I have a console log in the function. I’m guessing functions themselves take some time to deploy in AWS, and this is possibly why there is a significant discrepancy in what is logged and what is currently in the repo. I’ve not seen this delay documented anywhere in Netlify docs, however. Assuming that, I then don’t understand why my usage numbers are showing 0 function invocations, even though I have dozens of logs of invocations trying to test this. I see the usage period is beginning today (May 8), but I’ve already logged several invocations just today.

The last thing I want to mention, though it is not directly related to this thread, is that when I AM able to log my event object, the data is coming back a bit odd. event.body is returning a base64 encoded string. I’ve attempted to decode it, but it literally just decodes to [object Object] as in a string… it’s almost as if the payload supposed to be an encoded JSON string, but it’s converting a JS object to a string, i.e. [object Object], instead before anything gets encoded sent over? Again, it’s sending back “W29iamVjdCBPYmplY3Rd” in the event.body. This appears to be a bug of it’s own, but I wanted to mention it as it’s the reason why I’m trying to log so much into the functions log, as I can’t figure out how to actually get ahold of the form data once my function is invoked.

If you’d like, I can create a new thread for that last bit. Thank you for any insight.

Hi there @estenp, thanks for writing in. Looks like you are having multiple issues, I’ll address the last one here since I think you opened a support case already. Essentially, I need to see a reproduction in order to tell you why it’s printing [object object] Do you have the function in a public repo? Also what’s the payload that you’re passing into it?

Hi @futuregerald, thanks for reaching out and sorry I haven’t been able to get back to you. Here is my repo: https://github.com/estenp/market-boiler/blob/master/src/lambda/submission-created.js.

First off, I may have been mistaken. I don’t think I’ve actually logged the base64 string in prod, only when logging my event locally. Perhaps that would explain the weird event.body content, but this still seems odd to me. Should expect some sort of object in event even when using netlify-lambda locally?

As far as the payload on prod, this is a submission-created.js function. Maybe I’m misunderstanding, but I’m expecting the function to be invoked upon any netlify form submission on my site, and for the function to automatically receive a payload of that form data. Is this correct, and if so would the payload be within event.body?

My Netlify Functions Log appears to be inaccurate (related to the OP of this thread) so it’s very difficult to debug what sort of payload my function is actually receiving. It’s logging each time I submit the form, and appears to be invoking the function, but it isn’t logging what I’m expecting. If you look at my repo, I’m simply trying to log the event argument, but when invoked, it’s actually logging what appears to be my Netlify site metadata (you can see an example of this in my log screenshot above).

Let me know if that makes sense or I can provide any additional info, thanks!!!

Hi @estenp,

If you want to log the values in an object then you need to serialize it with JSON.stringify(). Or if you want a specific value then you can log that, for instance object.key.nested_key. But if you attempt to log the entire object you’ll get the string interpretation of it and not the values inside.

The event contains more than just the payload about the form. What you’re looking for is in event.body

The form submission webhook should return the following:

    {
    "number": 34,
    "title": null,
    "email": "test@netlify.com",
    "name": "test",
    "first_name": "test",
    "last_name": null,
    "company": null,
    "summary": "text field",
    "body": "text field",
    "data": {
        "name": "test",
        "email": "test@netlify.com",
        "random": "this is random",
        "message": "text field",
        "ip": "195.94.115.46",
        "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36",
        "referrer": "https://test-form--futuregerald.netlify.com/form.html"
    },
    "created_at": "2019-05-23T17:54:55.388Z",
    "human_fields": {
        "Name": "test",
        "Email": "test@netlify.com",
        "Random": "this is random",
        "Message": "text field"
    },
    "ordered_human_fields": [{
        "title": "Name",
        "name": "name",
        "value": "test"
    }, {
        "title": "Email",
        "name": "email",
        "value": "test@netlify.com"
    }, {
        "title": "Random",
        "name": "random",
        "value": "this is random"
    }, {
        "title": "Message",
        "name": "message",
        "value": "text field"
    }],
    "id": "5ce6ff10ea475751de6f0eae",
    "form_id": "5c5cb856a1aee4a722a62657",
    "site_url": "https://www.myfakesite.com",
    "form_name": "contact"
    }

I actually recommend that instead of using a named event-triggered function. You rename the function to something else and then trigger it using a form notification webhook. Function logs will be more reliable this way. In your form settings, you should see a notifications section and in there you can create a webhook notification. The webhook will be sent with the payload that I just provided.

Also, note that the event.body is a JSON string and needs to be parsed into an object.

2 Likes

@futuregerald After changing my function’s name and using a webhook notification rather than a “submission-created” function, my issue is completely resolved, and I’m now getting the appropriate data in the event object. I’ll maintain that there seems to be something up with the named event-triggered function, but now that I’ve made the suggested change, both my logs and my data is more accurate. Thank you for the help!

1 Like

Hi, I have the same problem mentioned by @teakwood in the first question of this thread: I have a serverless lambda function in Javascript with many console.log() statements, but in the dashboard I can see only some of them.

I attache two screenshots: in the first one we can see the first 6 occurrences of console.log() in the code, in the second one we can see that the dashboard doesn’t show the logs 1-4 (and the first occurrence of log number 6 we see, marked with an asterisk, is truncated).

Is there a solution to this issue?
Thank you very much.


Hi @GioFic95, functions logs are on the docket for fixes. We’re working on getting them to be more reliable. We’ve already started by working on updating build logs and we intend to move the focus to function logs afterwards.

3 Likes

Thank you very much!