Hi. Pls, help with making a decision. What is the best approach for Unity WebGL client app loging? I think there are three possible solutions:
1)Using browser console (I think it will not give a full logging experience)
2)Log to file (can be very customizable, but looks like there could be a problem with writing to a single file, when there are a lot of requests from many clients)
3)User online logging service similar to graylog (looks massive, but good)
Is it a standard way to use cloud logging services with client-side apps, like with compiled javascript?
What sort of logging do you want? If you log to a file, what do you plan to do with it? Who is the log for?
You cannot log to a file, not in a way that you can easily get that file. It‘s all sandboxed. So either browser console or external service.
I don‘t understand the „many clients“ though. Do you mean logging on the server side? In that case the server will not / cannot be a WebGL app anyway.
Yeah, lots of questions noted above will impact the suggestions you’ll get here. But to contribute to the discussion anyway - if it’s just for the client, and you’re not expecting the client to have a log file in the event of crashes (i.e. your game is stable), you could add all strings to a list, and they could click a button in your game to download log file, which joins that list with whatever line break you want and downloads a .txt file via call to javascript function in a .jslib (just search for “javascript download text file from string in memory”). I suggest using list instead of simply appending to a string, because as your string gets longer, appending to it takes more memory and gets slower (though not by a noticeable amount unless we’re talking thousands of entries… so wouldn’t bother for less verbose logging), so anyway using .Add and a List then string result = string.Join(your_line_break, your_list)… when you want a final version, would be a more performant approach.
If you want it for crashes, console log is best (Debug.Log) because it’s instant, compared to logging to a server/service, which might never get final entries because of crash before sending completes. You can override console logging via Javascript, so you can decide what to display or not display in it etc… a search for “override javascript console logging” will tell you how.
Another thing to mention, if you want longer-lived client-side logging (i.e. load the game again later, continue working with same log / have access to older entries) you could store to PlayerPrefs, but note there’s a 1mb limit (search “webgl playerprefs size limit”)… however, you can work around that by implementing a 3rd party local storage system such as localForage or writing your own, implemented via jslib.
Edit: looks like that 1mb limit is outdated - would have to look into the current limit yourself.