From 1258f5cc7491648fb12183ca9ed15ff520b9e5ce Mon Sep 17 00:00:00 2001 From: Anton Struyk Date: Mon, 26 Feb 2018 15:39:29 -0500 Subject: [PATCH 1/2] Add ability to toggle showing/hiding channel that a message was sent to in the log output. --- Editor/UberLoggerEditorWindow.cs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Editor/UberLoggerEditorWindow.cs b/Editor/UberLoggerEditorWindow.cs index 39adc79..e814583 100755 --- a/Editor/UberLoggerEditorWindow.cs +++ b/Editor/UberLoggerEditorWindow.cs @@ -267,6 +267,13 @@ void DrawToolbar() ShowTimes = showTimes; } DrawPos.x += elementSize.x; + var showChannels = ToggleClamped(ShowChannels, "Channels", EditorStyles.toolbarButton, out elementSize); + if (showChannels != ShowChannels) + { + MakeDirty = true; + ShowChannels = showChannels; + } + DrawPos.x += elementSize.x; var collapse = ToggleClamped(Collapse, "Collapse", EditorStyles.toolbarButton, out elementSize); if(collapse!=Collapse) { @@ -365,15 +372,19 @@ bool ShouldShowLog(System.Text.RegularExpressions.Regex regex, LogInfo log) /// /// Converts a given log element into a piece of gui content to be displayed /// - GUIContent GetLogLineGUIContent(UberLogger.LogInfo log, bool showTimes) + GUIContent GetLogLineGUIContent(UberLogger.LogInfo log, bool showTimes, bool showChannels) { var showMessage = log.Message; //Make all messages single line showMessage = showMessage.Replace(UberLogger.Logger.UnityInternalNewLine, " "); - if(showTimes) - { - showMessage = log.GetRelativeTimeStampAsString() + ": " + showMessage; - } + + showMessage = string.Format("{0}{1}{2}{3}{4}", + showChannels ? "[" + log.Channel + "]" : "", + showTimes && showChannels ? " " : "", + showTimes ? log.GetRelativeTimeStampAsString() : "", + showChannels || showTimes ? " : " : "", + showMessage + ); var content = new GUIContent(showMessage, GetIconForLog(log)); return content; @@ -435,7 +446,7 @@ public void DrawLogList(float height) foreach(var countedLog in collapsedLinesList) { - var content = GetLogLineGUIContent(countedLog.Log, ShowTimes); + var content = GetLogLineGUIContent(countedLog.Log, ShowTimes, ShowChannels); RenderLogs.Add(countedLog); var logLineSize = logLineStyle.CalcSize(content); LogListMaxWidth = Mathf.Max(LogListMaxWidth, logLineSize.x); @@ -453,7 +464,7 @@ public void DrawLogList(float height) { if(ShouldShowLog(filterRegex, log)) { - var content = GetLogLineGUIContent(log, ShowTimes); + var content = GetLogLineGUIContent(log, ShowTimes, ShowChannels); RenderLogs.Add(new CountedLog(log, 1)); var logLineSize = logLineStyle.CalcSize(content); LogListMaxWidth = Mathf.Max(LogListMaxWidth, logLineSize.x); @@ -507,7 +518,7 @@ public void DrawLogList(float height) } //Make all messages single line - var content = GetLogLineGUIContent(log, ShowTimes); + var content = GetLogLineGUIContent(log, ShowTimes, ShowChannels); var drawRect = new Rect(logLineX, buttonY, contentRect.width, LogListLineHeight); if(GUI.Button(drawRect, content, logLineStyle)) { @@ -905,6 +916,7 @@ void ClearSelectedMessage() Texture2D SmallWarningIcon; Texture2D SmallMessageIcon; + bool ShowChannels = true; bool ShowTimes = true; bool Collapse = false; bool ScrollFollowMessages = false; From 3072854a2e6640319fef220a6f98853ab68edbfd Mon Sep 17 00:00:00 2001 From: Anton Struyk Date: Mon, 26 Feb 2018 16:01:29 -0500 Subject: [PATCH 2/2] Add helper class to make logging to a channel safer by supporting code completion and avoiding having to correct type channel name each time. --- UberLoggerChannel.cs | 76 +++++++++++++++++++++++++++++++++++++++ UberLoggerChannel.cs.meta | 13 +++++++ 2 files changed, 89 insertions(+) create mode 100644 UberLoggerChannel.cs create mode 100644 UberLoggerChannel.cs.meta diff --git a/UberLoggerChannel.cs b/UberLoggerChannel.cs new file mode 100644 index 0000000..a9ca85d --- /dev/null +++ b/UberLoggerChannel.cs @@ -0,0 +1,76 @@ +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; + } + + /// + /// Gets or sets whether messages sent to this channel should actually be relayed to the logging system or not. + /// + public bool Mute { get; set; } + + [StackTraceIgnore] + public void Log(string message, params object[] par) + { + if (!Mute) + { + UberDebug.LogChannel(_channelName, message, par); + } + } + + [StackTraceIgnore] + public void Log(Object context, string message, params object[] par) + { + if (!Mute) + { + UberDebug.LogChannel(context, _channelName, message, par); + } + } + + [StackTraceIgnore] + public void LogWarning(string message, params object[] par) + { + if (!Mute) + { + UberDebug.LogWarningChannel(_channelName, message, par); + } + } + + [StackTraceIgnore] + public void LogWarning(Object context, string message, params object[] par) + { + if (!Mute) + { + UberDebug.LogWarningChannel(context, _channelName, message, par); + } + } + + [StackTraceIgnore] + public void LogError(string message, params object[] par) + { + if (!Mute) + { + UberDebug.LogErrorChannel(_channelName, message, par); + } + } + + [StackTraceIgnore] + public void LogError(Object context, string message, params object[] par) + { + if (!Mute) + { + 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: