- Home /
How to properly call Debug.Log(string) in a custom Log function?
I’d like to create an alternate version of Debug.Log(string): ConidtionalDebugLog(string). I’d simply like to wrap the debug statement in a few conditionals, based on settings. That part works fine.
The issue I’m hitting is with the “non-string” part of the log, in particular the stack trace. As one would expect, the error in the console shows the line that the Debug.Log() function was called, both in the stack trace, and when double clicking the message to open the script file to that line.
Ideally, I would like to have the console show (and go to, on double click) the line of code that called ConditionalDebugLog(string), instead of the line of code INSIDE ConditionalDebugLog() that called Debug.Log().
I’ve tried going through the docs on the various ILogger, ILogHandler
interfaces, in order to try understanding how Debug.logger works, but I’m still not clear on if this stuff can even help the objective.
Is this possible? Is it practical? If so, any suggestions? Any ideas for alternatives also welcome.
Answer by Eric5h5 · Aug 07, 2016 at 06:40 PM
Compile the ConditionalDebugLog code into a DLL.
oh interesting! Never done that before, I guess I'll need to pass my conditional values into that DLL at startup and on change since it won't have stuff from my project in scope; is that right?
I'll start here unless you have any other suggestions: https://docs.unity3d.com/$$anonymous$$anual/UsingDLL.html
No; all code in Unity is compiled and there's no difference in code behavior in a script compared to code in a DLL. Except for the Debug.Log thing.
Hmm, I must be missing something: The instructions have me creating the CustomDebug DLL as a separate project to be compiled into the DLL. I don't see how I can reference any of the code from my Unity project, like say.. GlurthSettings.numberOfDoDadsInScene, when it's not defined in the DLL Project, without generating a compiler error (not in scope).
Then again, I have not gone very far with this so far, perhaps it will become apparent when I do.
Works exactly as desired! (need to pass in the conditionals from main project to DLL, but that's easy enough.) $$anonymous$$any thanks!
Could you please explain how it's achieved so people visiting this question can find the answer without duplicating this question? Thanks
explain what part? how to make a DLL? The link in my first comment shows how.