Skip to content

Commit

Permalink
Added option to show timestamps of logs (disabled by default for maxi…
Browse files Browse the repository at this point in the history
…mum performance) (closed #59)
  • Loading branch information
yasirkula committed Aug 8, 2021
1 parent 65429fa commit d832670
Show file tree
Hide file tree
Showing 9 changed files with 381 additions and 133 deletions.
8 changes: 8 additions & 0 deletions Plugins/IngameDebugConsole/Editor/DebugLogManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class DebugLogManagerEditor : Editor
private SerializedProperty toggleKey;
private SerializedProperty enableSearchbar;
private SerializedProperty topSearchbarMinWidth;
private SerializedProperty captureLogTimestamps;
private SerializedProperty alwaysDisplayTimestamps;
private SerializedProperty clearCommandAfterExecution;
private SerializedProperty commandHistorySize;
private SerializedProperty showCommandSuggestions;
Expand All @@ -41,6 +43,8 @@ private void OnEnable()
#endif
enableSearchbar = serializedObject.FindProperty( "enableSearchbar" );
topSearchbarMinWidth = serializedObject.FindProperty( "topSearchbarMinWidth" );
captureLogTimestamps = serializedObject.FindProperty( "captureLogTimestamps" );
alwaysDisplayTimestamps = serializedObject.FindProperty( "alwaysDisplayTimestamps" );
clearCommandAfterExecution = serializedObject.FindProperty( "clearCommandAfterExecution" );
commandHistorySize = serializedObject.FindProperty( "commandHistorySize" );
showCommandSuggestions = serializedObject.FindProperty( "showCommandSuggestions" );
Expand Down Expand Up @@ -76,6 +80,10 @@ public override void OnInspectorGUI()
if( enableSearchbar.boolValue )
DrawSubProperty( topSearchbarMinWidth );

EditorGUILayout.PropertyField( captureLogTimestamps );
if( captureLogTimestamps.boolValue )
DrawSubProperty( alwaysDisplayTimestamps );

EditorGUILayout.PropertyField( clearCommandAfterExecution );
EditorGUILayout.PropertyField( commandHistorySize );
EditorGUILayout.PropertyField( showCommandSuggestions );
Expand Down
160 changes: 80 additions & 80 deletions Plugins/IngameDebugConsole/Prefabs/DebugLogItem.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &173670
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 22457652}
- component: {fileID: 22240404}
- component: {fileID: 11465282}
m_Layer: 5
m_Name: LogText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &11404142
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -129,7 +112,7 @@ MonoBehaviour:
transformComponent: {fileID: 22479264}
imageComponent: {fileID: 11459012}
canvasGroupComponent: {fileID: 225819852034701160}
logText: {fileID: 11465282}
logText: {fileID: 114694493629914950}
logTypeImage: {fileID: 11404142}
logCountParent: {fileID: 104862}
logCountText: {fileID: 11432936}
Expand Down Expand Up @@ -262,39 +245,6 @@ MonoBehaviour:
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!114 &11465282
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 173670}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.83823526, g: 0.84439874, b: 0.84439874, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 15
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 1
m_MaxSize: 40
m_Alignment: 3
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Debug.Log summary
--- !u!222 &22200920
CanvasRenderer:
m_ObjectHideFlags: 1
Expand All @@ -307,12 +257,6 @@ CanvasRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 104862}
--- !u!222 &22240404
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 173670}
--- !u!222 &22262284
CanvasRenderer:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -358,26 +302,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
m_AnchoredPosition: {x: 25, y: 0}
m_SizeDelta: {x: 32, y: 32}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &22457652
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 173670}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 22479264}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 22.5, y: 0}
m_SizeDelta: {x: -55, y: -2}
m_AnchoredPosition: {x: 18, y: 0}
m_SizeDelta: {x: 25, y: 25}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &22461494
RectTransform:
Expand Down Expand Up @@ -409,7 +335,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 22427300}
- {fileID: 22457652}
- {fileID: 224737693311518052}
- {fileID: 22461494}
- {fileID: 224006190298411330}
m_Father: {fileID: 0}
Expand All @@ -418,7 +344,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 40}
m_SizeDelta: {x: 0, y: 35}
m_Pivot: {x: 0, y: 1}
--- !u!1001 &100100000
Prefab:
Expand Down Expand Up @@ -466,6 +392,23 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1785910143472904
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 224737693311518052}
- component: {fileID: 222175805939703770}
- component: {fileID: 114694493629914950}
m_Layer: 5
m_Name: LogText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &114119781176956926
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -526,6 +469,39 @@ MonoBehaviour:
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Copy
--- !u!114 &114694493629914950
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1785910143472904}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.83823526, g: 0.84439874, b: 0.84439874, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 15
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 1
m_MaxSize: 40
m_Alignment: 3
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Debug.Log summary
--- !u!114 &114694923173451186
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -578,6 +554,12 @@ MonoBehaviour:
m_CallState: 2
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!222 &222175805939703770
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1785910143472904}
--- !u!222 &222313182602304162
CanvasRenderer:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -607,8 +589,26 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: 0, y: 2}
m_SizeDelta: {x: -100, y: 36}
m_SizeDelta: {x: -70, y: 36}
m_Pivot: {x: 0.5, y: 0}
--- !u!224 &224737693311518052
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1785910143472904}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 22479264}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 15, y: 0}
m_SizeDelta: {x: -40, y: -2}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &224887990600088790
RectTransform:
m_ObjectHideFlags: 1
Expand Down
75 changes: 74 additions & 1 deletion Plugins/IngameDebugConsole/Scripts/DebugLogEntry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using UnityEngine;
//#define IDG_OMIT_ELAPSED_TIME
//#define IDG_OMIT_FRAMECOUNT

using System.Text;
using UnityEngine;

// Container for a simple debug entry
namespace IngameDebugConsole
Expand Down Expand Up @@ -89,4 +93,73 @@ public bool MatchesSearchTerm( string searchTerm )
( stackTrace != null && stackTrace.IndexOf( searchTerm, System.StringComparison.OrdinalIgnoreCase ) >= 0 );
}
}

public struct DebugLogEntryTimestamp
{
public readonly System.DateTime dateTime;
#if !IDG_OMIT_ELAPSED_TIME
public readonly float elapsedSeconds;
#endif
#if !IDG_OMIT_FRAMECOUNT
public readonly int frameCount;
#endif

public DebugLogEntryTimestamp( System.TimeSpan localTimeUtcOffset )
{
// It is 10 times faster to cache local time's offset from UtcNow and add it to UtcNow to get local time at any time
dateTime = System.DateTime.UtcNow + localTimeUtcOffset;
#if !IDG_OMIT_ELAPSED_TIME
elapsedSeconds = Time.realtimeSinceStartup;
#endif
#if !IDG_OMIT_FRAMECOUNT
frameCount = Time.frameCount;
#endif
}

public void AppendTime( StringBuilder sb )
{
// Add DateTime in format: [HH:mm:ss]
sb.Append( "[" );

int hour = dateTime.Hour;
if( hour >= 10 )
sb.Append( hour );
else
sb.Append( "0" ).Append( hour );

sb.Append( ":" );

int minute = dateTime.Minute;
if( minute >= 10 )
sb.Append( minute );
else
sb.Append( "0" ).Append( minute );

sb.Append( ":" );

int second = dateTime.Second;
if( second >= 10 )
sb.Append( second );
else
sb.Append( "0" ).Append( second );

sb.Append( "]" );
}

public void AppendFullTimestamp( StringBuilder sb )
{
AppendTime( sb );

#if !IDG_OMIT_ELAPSED_TIME && !IDG_OMIT_FRAMECOUNT
// Append elapsed seconds and frame count in format: [1.0s at #Frame]
sb.Append( "[" ).Append( elapsedSeconds.ToString( "F1" ) ).Append( "s at " ).Append( "#" ).Append( frameCount ).Append( "]" );
#elif !IDG_OMIT_ELAPSED_TIME
// Append elapsed seconds in format: [1.0s]
sb.Append( "[" ).Append( elapsedSeconds.ToString( "F1" ) ).Append( "s]" );
#elif !IDG_OMIT_FRAMECOUNT
// Append frame count in format: [#Frame]
sb.Append( "[#" ).Append( frameCount ).Append( "]" );
#endif
}
}
}
Loading

0 comments on commit d832670

Please sign in to comment.