Logging
This guide describes how you can write logs while debugging your scripts. It can be helpful too to get feedback from players when they find bugs.
Logging and tracing functions
With Cyberpunk >= 2.01, you need to paste the snippet below into e.g.
r6\scripts\Logs.reds
if you want to avoid UNRESOLVED_FN errors at compile time.
This will give access to these functions to all scripts (including yours):
native func Log(const text: script_ref<String>) -> Void
native func LogWarning(const text: script_ref<String>) -> Void
native func LogError(const text: script_ref<String>) -> Void
// output goes to CET window
native func LogChannel(channel: CName, const text: script_ref<String>)
native func LogChannelWarning(channel: CName, const text: script_ref<String>) -> Void
native func LogChannelError(channel: CName, const text: script_ref<String>) -> Void
native func FTLog(const value: script_ref<String>) -> Void
native func FTLogWarning(const value: script_ref<String>) -> Void
native func FTLogError(const value: script_ref<String>) -> Void
native func Trace() -> Void
native func TraceToString() -> StringDo not package this file with your mod though because that would lead to conflicts with other scripts.
Example usage
Where does it go?
You can see the output on your CET console, or in the scripting.log inside the CET folder.
Improve logging
You can use the function FTLog to create logs with your mod's name as a prefix. It will make it easier for you to go over your logs and filter them:
You can use it like this:
We can even improve on this with Codeware. It provides the function GetStackTrace so we can deduce the class and function where our logging function is executed:
You can use it the same way, this time it will log something like:
This is convenient as you don't have to worry when you copy/paste this line in another function. The class and function name will be deduced for you. It also works when using a global function.
Last updated
Was this helpful?