Closed ritzow closed 6 years ago
Maybe I should just make a branch and create a pull request. The code was only a few lines:
public delegate string MessageProvider();
public static void Output(Severity Sev, Source Src, MessageProvider message) {
//repeat this code because the delegate shouldn't be called unless its log level is enabled
if (OutputLevels[(int)Src] <= Sev) { ForceOutput(Sev, Src, message()); }
}`
Go ahead, this sounds like a good idea.
This is a minor thing, but it seems like it would be more efficient to use a delegate for getting the message to log to the console (the Log.Output message parameter). Using a delegate would mean that if logging is turned off, the overhead of calling Log.Output would be close to zero, whereas currently, string concatenation will occur even if logging is disabled. For an example of this, see this example from the Java standard library. The Supplier's method will only be called if the message is needed. This could also have an even greater performance benefit once sending log messages over the network is implemented.