Function logs are inconsistent in the Netlify Dashboard

unanswered
#1

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.

#2

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?

#3

@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.

#4

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

#5

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?

#6

@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.

#7

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?

#8

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!!!