diff --git a/Examples/TestUberLogger.cs b/Examples/TestUberLogger.cs index 95d1c4f..72f6e8e 100755 --- a/Examples/TestUberLogger.cs +++ b/Examples/TestUberLogger.cs @@ -4,6 +4,8 @@ public class TestUberLogger : MonoBehaviour { + public static readonly UberLoggerChannel TestChannelWrapper = new UberLoggerChannel("WrapperChannel"); + Thread TestThread; // Use this for initialization void Start () @@ -71,6 +73,47 @@ public void DoTest() UberDebug.LogErrorChannel("Test", "ULogErrorChannel with param {0}", "Test"); UberDebug.LogErrorChannel(gameObject, "Test", "ULogErrorChannel with GameObject"); UberDebug.LogErrorChannel(gameObject, "Test", "ULogErrorChannel with GameObject and param {0}", "Test"); + + // Will output all messages in test function. + RunChannelWrapperTests(); + + // Will hide .Log(...) calls in test function. + TestChannelWrapper.Filter = UberLoggerChannel.Filters.Logs; + RunChannelWrapperTests(); + + // Will hide .LogWarning(...) calls in test function. + TestChannelWrapper.Filter = UberLoggerChannel.Filters.Warnings; + RunChannelWrapperTests(); + + // Will hide .LogError(...) calls in test function. + TestChannelWrapper.Filter = UberLoggerChannel.Filters.Errors; + RunChannelWrapperTests(); + + // Will hide .Log(...) and LogWarning(...) calls in test function. + TestChannelWrapper.Filter = UberLoggerChannel.Filters.Logs | UberLoggerChannel.Filters.Warnings; + RunChannelWrapperTests(); + } + + private void RunChannelWrapperTests() + { + Debug.Log("Running Channel Wrapper Tests..."); + + TestChannelWrapper.Log("Wrapped Channel"); + TestChannelWrapper.Log("Wrapped Channel with param {0}", "Test"); + TestChannelWrapper.Log(gameObject, "Wrapped Channel with GameObject"); + TestChannelWrapper.Log(gameObject, "Wrapped Channel with GameObject and param {0}", "Test"); + + TestChannelWrapper.LogWarning("Wrapped Channel Warning"); + TestChannelWrapper.LogWarning("Wrapped Channel Warning with param {0}", "Test"); + TestChannelWrapper.LogWarning(gameObject, "Wrapped Channel Warning with GameObject"); + TestChannelWrapper.LogWarning(gameObject, "Wrapped Channel Warning with GameObject and param {0}", "Test"); + + TestChannelWrapper.LogError("Wrapped Channel Error"); + TestChannelWrapper.LogError("Wrapped Channel Error with param {0}", "Test"); + TestChannelWrapper.LogError(gameObject, "Wrapped Channel Error with GameObject"); + TestChannelWrapper.LogError(gameObject, "Wrapped Channel Error with GameObject and param {0}", "Test"); + + Debug.Log("... Done Running Channel Wrapper Tests."); } // Update is called once per frame diff --git a/UberLoggerChannel.cs b/UberLoggerChannel.cs new file mode 100644 index 0000000..3f67c43 --- /dev/null +++ b/UberLoggerChannel.cs @@ -0,0 +1,89 @@ +using System.Collections; +using System.Collections.Generic; +using UberLogger; +using UnityEngine; + +/// +/// Wraps access to a named channel in a class so that it can be used without having to +/// type the channel name each time to enforcing channel name checking at compile-time. +/// +public class UberLoggerChannel +{ + private string ChannelName; + public UberLoggerChannel(string channelName) + { + ChannelName = channelName; + Filter = Filters.None; + } + + /// + /// Filters for preventing display of certain message types. + /// + [System.Flags] + public enum Filters + { + None = 0, + Logs = 1 << 0, + Warnings = 1 << 1, + Errors = 1 << 2 + } + + /// + /// Gets or sets the current filters being applied to this channel. Messages that match the specified set of flags will be ignored. + /// + public Filters Filter { get; set; } + + [StackTraceIgnore] + public void Log(string message, params object[] par) + { + if ((Filter & Filters.Logs) == 0) + { + UberDebug.LogChannel(ChannelName, message, par); + } + } + + [StackTraceIgnore] + public void Log(Object context, string message, params object[] par) + { + if ((Filter & Filters.Logs) == 0) + { + UberDebug.LogChannel(context, ChannelName, message, par); + } + } + + [StackTraceIgnore] + public void LogWarning(string message, params object[] par) + { + if ((Filter & Filters.Warnings) == 0) + { + UberDebug.LogWarningChannel(ChannelName, message, par); + } + } + + [StackTraceIgnore] + public void LogWarning(Object context, string message, params object[] par) + { + if ((Filter & Filters.Warnings) == 0) + { + UberDebug.LogWarningChannel(context, ChannelName, message, par); + } + } + + [StackTraceIgnore] + public void LogError(string message, params object[] par) + { + if ((Filter & Filters.Errors) == 0) + { + UberDebug.LogErrorChannel(ChannelName, message, par); + } + } + + [StackTraceIgnore] + public void LogError(Object context, string message, params object[] par) + { + if ((Filter & Filters.Errors) == 0) + { + UberDebug.LogErrorChannel(context, ChannelName, message, par); + } + } +} diff --git a/UberLoggerChannel.cs.meta b/UberLoggerChannel.cs.meta new file mode 100644 index 0000000..291728a --- /dev/null +++ b/UberLoggerChannel.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 6ffc2b9216ac83f4db26a958afcdac7b +timeCreated: 1519677969 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: