Not quite sure the definitive method to do this, For development I have made an extensive custom Logging system that is quite heavy on resources but gives me the information I need to develop purely in c++.
As I am not sure about compiler statements, I wrapped my logs in
// **SLOG**
.
.
.
// **ELOG**
with the intention of copy/replace this out with the correct code. I know I need some conditional compiler statements and some googling has turned up that I should use
#if WITH_EDITOR
.
.
.
#endif
I just need to know this is the best / correct way to remove all my logging / debug code when I build my Application, both under Development and Shipping
Thanks
You are looking for UE_BUILD_SHIPPING define which is defined in the Shipping configuration. UE_BUILD_TEST is defined for the Test builds (almost Shipping but not quite).
I would suggest that if you want all your logs to work this way, it would be better to put those conditionals in the headers instead of requiring every file you include them in to conditionally exclude them. That way you can’t forget and it will also be working the way you want.
Not sure I understand this. I want to have my logging present only when Im developing with the editor. I want it all gone when Shipping or Testing
Right:
#if !UE_BUILD_SHIPPING && !UE_BUILD_TEST
...
#else
...
#endif
Or do you mean the other part of my advice of doing all the define work in the header?
Thanks, I’ll give that a try. I have no idea what you mean about putting it all in the header, as until now, ive managed 2 years of c++ without a single preprocessor directive.
I’ll be interested to see how the game runs (faster hopefully) when all the logging function calls code are stripped out…
One more thing, after I have wrapped my logging code in the directives, do I need to worry about setting the variable UE_BUILD_SHIPPING, or is this automatic when I tell the editor to package a shipping build?
THanks
Take a look at LogMacros.h from the engine for what I mean about doing it in the header. The basic theory though it to limit the number of preprocessor directives you actually need to write so that you don’t have to wrap all your logging calls in pre-processor checks.
UE_BUILD_SHIPPING isn’t a variable, per se. It’s a preprocessor declaration and it will be defined by UBT (Unreal Build Tool) when you compile your shipping executable. I’m not 100% sure if that’s something that happens when you package a build. I thought the output of that was just the pak files and you had to build the executable yourself.
That’s pretty good. Overall, using the preprocessor is considered a tool of last resort in modern C++ as there are usually better options now. This sort of thing, conditional compilation, is one of the few remaining reasons you need to use it.
Thanks for help, Ive spent a few hours blocking out all my logging code, which I thought was pretty extensive and quite complex, and a few bugs allowed me to check that the compiler directives were actually working (I managed to accidentally conditionally kill the pointer to my player controller -OOPS, which wasted 2 hours of my time debugging) but now I have the shipping build running sweet…but the framerate is exactly the same as the development build…which was pretty ok before, but I was hoping for a something!
Oh well, at least I learnt something.
Not all that surprising. You’re logging would have to be doing a lot, a lot, of work and/or being doing a lot of it for it to start showing up as an effect on your framerate. But this is why you’re supposed to profile before doing optimizations.
But this is the sort of thing that’s (potentially) easier to setup now then it would/could be doing it when it is causing a perf problem.