console.log in jsw file

When I console.log in the front end I see the output in the Developer Console. When I put console.log in a .jsw file, I don’t see their response in Chrome Developer Tools or Developer Console.
Any ideas why?

Other options for debugging?

Thanks,

Hey Todd,

I’ve encountered the same issue. I believe that this is a known issue and that there will eventually be a fix for this. Meanwhile…

You can create your own log() statement that adds a line of text to a log database:

function log(text){
    wixData.insert("log", {title: text});
}

You’ll need a database collection named log, that has just one field - the default field Title (field key: title). You can then debug your code by “logging” messages to the log collection.

I hope this helps,

Yisrael

In all my projects I always create a Data Collection called SystemLog and in that data collection I have the title field and also fields for the below.

Action
Function
Module
User
Device
ScreenHeight
ScreenWidth
SessionStorage
LocalStorage
FullUrl
QueryString
Path

I then add a function inside the Public folder which will take care of getting all these variables I need and then combining them with my own data.

So I can just import {addLog} from ‘public/systemTools’ in the site code or page code. If I run addLog(“DEBUG”, “This is a debug line”, object) the log code will see that the ACTION is DEBUG so it won’t take in all parameters but just add the ACTION = DEBUG, the text as Title and it will try JSON.parse the object and store it.

I then create a hidden page for me on mobile that I can open anytime someone calls or emails about an error and I can see the last 200 records on my mobile and start thinking about errors I might cause.

Andreas’ solution is interesting, but it is a lot of overhead for simple projects.
Just would like to see console.log working in the backend 100% of the time when in preview.
Currently it works randomly - strange.
“…known issue and that there will eventually be a fix for this.”
That line has been floating here since 2017.
What’s the status on this?

There are non-trivial technical issues involved. No time-line available but it is being worked on. Meanwhile, the little code snippet I posted above works great, and isn’t really unreasonable overhead. I use it frequently.