UberLogger
UberLogger copied to clipboard
Utility class for logging to channel
Added a utility class that wraps calls to Log*Channel(...) so that you can get code completion and don't have to worry about typing the channel name correctly each time.
My use case looks like this:
- Make a static class with a number of UberLoggerChannel as members:
public static class Logger {
public static readonly UberLoggerChannel Core = new UberLoggerChannel("Core");
public static readonly UberLoggerChannel Achievements = new UberLoggerChannel("Achievements ");
// .... More channels
}
Then usage looks like:
Logger.Core.Log("Foo");
Logger.Achievements.LogWarning("Bar");
And you get compile-time support (code completion, error checking, find-references, etc..). This is really useful when you want to standardize the usage of channels across a team because you don't have to remember capitalization and channel names.
Also you can easily turn on/off these channels without sprinkling your code with if (muteMyChannel) { Debug.Log("...."); }
checks:
For example:
public static class Logger {
public static readonly UberLoggerChannel ObscureSystem = new UberLoggerChannel("ObscureSystem");
// ... Other channels
static Logger() {
ObscureSystem.Mute = true;
}
};
This is neat. I like the lightweight-ness of your implementation, that's quite in line with core UberLogger. One suggestion: change the "mute" flag into a filter level; thus, you can choose to mute just messages from an obscure system. I find that it is common to want to mute messages, but not warnings/errors. Example here. With filter level muting I'd vote for including this into core UberLogger.
I've made a similar but more enterprise-y thing. It has an inspector + a source code generation step. The code generation allows for removal of the call sites for muted channels -> good for projects with lots of logging. It is a bit more clunky to use; the editor is still a bit clunky, and if the user generates source code for a bad configuration it is difficult to go back without reverting all changes to the configuration asset. I think what you have made is more suitable for core UberLogger.
Added flags to allow you to filter out messages now. You can now filter out normal .Log(...) calls (for example) by using something like ObscureSystem.Filter = UberLoggerChannel.Filters.HideLogs;
or ObscureSystem.Filter = UberLoggerChannel.Filters.HideLogs | UberLoggerChannel.Filters.HideWarnings;