for a project my project group and I have created a program with a somewhat complicated algorithm. In this algorithm we use a lot of logger.finest
, logger.finer
etc. When running the default IntelliJ Profiler (for windows) 'Java Flight Recorder' we get the following result (Percentage is amount of total time of execution spend in said functions):
There is a lot of string concatination going on for logging which isn't even saved to a file because the logging is off:
Level.OFF
The string concatination doesn't stop as it's just a parameter of the functions.
We've thought of multiple solutions which all have their flaws:
- Using an external (Helper) Method/Class that has an
if
statement for logging. Something like:
// Psuedo Code
public static void log(String msg_id) {
if (should log) {
log(msg);
}
}
While this specific wouldn't work either way, maybe working with ID's or Callable
s could. The main drawback for this is that the logging references for classes and methods are lost. Every line will say the logging came from Helper.log
- Another thing we thought we could try is put if statements before every log line:
if(should log) {
log("msg");
}
This, of course would work but would clutter all files and would be a pain to maintain, constantly asking someone to write if
s for very logging line.
- We could write a script which removes all log lines for when we want to run the program at full speed:
But this feels hands down ridiculous...
TLDR;
I want to find a clean and somewhat proper way to stop the string concatination when logging is off as it's a massive performance decrease.
I've tried a seperate helper class, many if
s and external scripts but they don't feel like a proper solutions...