From 215e6013a85f9a538622d7591ebd9bf25ce3c576 Mon Sep 17 00:00:00 2001 From: Anton Struyk Date: Mon, 26 Feb 2018 15:39:29 -0500 Subject: [PATCH 1/3] 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 d85f16cd82d34e1f6cc0fa07a23f644cdec63832 Mon Sep 17 00:00:00 2001 From: Anton Struyk Date: Wed, 28 Feb 2018 12:16:39 -0500 Subject: [PATCH 2/3] Code review change - simplify string concatenation logic for readability. Add comment explaining expected output for reference. --- Editor/UberLoggerEditorWindow.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Editor/UberLoggerEditorWindow.cs b/Editor/UberLoggerEditorWindow.cs index e814583..6e1fe01 100755 --- a/Editor/UberLoggerEditorWindow.cs +++ b/Editor/UberLoggerEditorWindow.cs @@ -375,14 +375,24 @@ bool ShouldShowLog(System.Text.RegularExpressions.Regex regex, LogInfo log) GUIContent GetLogLineGUIContent(UberLogger.LogInfo log, bool showTimes, bool showChannels) { var showMessage = log.Message; + //Make all messages single line showMessage = showMessage.Replace(UberLogger.Logger.UnityInternalNewLine, " "); + // Format the message as follows: + // [channel] 0.000 : message <-- Both channel and time shown + // 0.000 : message <-- Time shown, channel hidden + // [channel] : message <-- Channel shown, time hidden + // message <-- Both channel and time hidden + var channelMessage = showChannels ? string.Format("[{0}]", log.Channel) : ""; + var channelTimeSeparator = (showChannels && showTimes) ? " " : ""; + var timeMessage = showTimes ? string.Format("{0}", log.GetRelativeTimeStampAsString()) : ""; + var prefixMessageSeparator = (showChannels || showTimes) ? " : " : ""; showMessage = string.Format("{0}{1}{2}{3}{4}", - showChannels ? "[" + log.Channel + "]" : "", - showTimes && showChannels ? " " : "", - showTimes ? log.GetRelativeTimeStampAsString() : "", - showChannels || showTimes ? " : " : "", + channelMessage, + channelTimeSeparator, + timeMessage, + prefixMessageSeparator, showMessage ); From 0c511016e4123ff54f1a594b94fd4fb00771ae45 Mon Sep 17 00:00:00 2001 From: Anton Struyk Date: Wed, 28 Feb 2018 12:23:10 -0500 Subject: [PATCH 3/3] Hide channel label in log messages that aren't sent to a channel (even if display channels setting is enabled). Prevents '[]' from showing up for non-channel based logs. --- Editor/UberLoggerEditorWindow.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Editor/UberLoggerEditorWindow.cs b/Editor/UberLoggerEditorWindow.cs index 6e1fe01..bd67cb6 100755 --- a/Editor/UberLoggerEditorWindow.cs +++ b/Editor/UberLoggerEditorWindow.cs @@ -384,10 +384,11 @@ GUIContent GetLogLineGUIContent(UberLogger.LogInfo log, bool showTimes, bool sho // 0.000 : message <-- Time shown, channel hidden // [channel] : message <-- Channel shown, time hidden // message <-- Both channel and time hidden - var channelMessage = showChannels ? string.Format("[{0}]", log.Channel) : ""; - var channelTimeSeparator = (showChannels && showTimes) ? " " : ""; + var showChannel = showChannels && !string.IsNullOrEmpty(log.Channel); + var channelMessage = showChannel ? string.Format("[{0}]", log.Channel) : ""; + var channelTimeSeparator = (showChannel && showTimes) ? " " : ""; var timeMessage = showTimes ? string.Format("{0}", log.GetRelativeTimeStampAsString()) : ""; - var prefixMessageSeparator = (showChannels || showTimes) ? " : " : ""; + var prefixMessageSeparator = (showChannel || showTimes) ? " : " : ""; showMessage = string.Format("{0}{1}{2}{3}{4}", channelMessage, channelTimeSeparator,