Skip to content

Commit

Permalink
New Logging Solution (#1653)
Browse files Browse the repository at this point in the history
* Include UnityDebugger

* Remove Uberlogger

* Replace old Uberlogger calls

* gitignore ChannelSettings.asset

* Add Scrollbar to window

* Change to vertical orientation
  • Loading branch information
koosemose authored and bjubes committed Dec 8, 2016
1 parent a45d663 commit d051088
Show file tree
Hide file tree
Showing 149 changed files with 384 additions and 5,363 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
!/Assets/StreamingAssets/Data/Mods/README.md.meta
/[Pp]roject[Ss]ettings/ProjectVersion.txt
/[Pp]roject[Ss]ettings/GraphicsSettings.asset
/Assets/Resources/ChannelSettings.asset
/Assets/Resources/ChannelSettings.asset.meta

# Autogenerated VS/MD solution and project files
ExportedObj/
Expand Down
104 changes: 104 additions & 0 deletions Assets/Editor/DebuggerChannelControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#region License
// ====================================================
// Project Porcupine Copyright(C) 2016 Team Porcupine
// This program comes with ABSOLUTELY NO WARRANTY; This is free software,
// and you are welcome to redistribute it under certain conditions; See
// file LICENSE, which is part of this source code package, for details.
// ====================================================
#endregion

using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;

public class DebuggerChannelControl : EditorWindow
{
private EditorWindow window;

private bool allState;
private bool allPreveState;
private ChannelSettingsSO channelSettings;
private Vector2 scrollViewVector = Vector2.down;

[MenuItem("Window/Debugger Channel Control")]
public static void ShowWindow()
{
GetWindow(typeof(DebuggerChannelControl));
}

private void Awake()
{
channelSettings = Resources.Load<ChannelSettingsSO>("ChannelSettings");
if (channelSettings == null)
{
channelSettings = ScriptableObject.CreateInstance<ChannelSettingsSO>();
AssetDatabase.CreateAsset(channelSettings, "Assets/Resources/ChannelSettings.asset");
AssetDatabase.SaveAssets();
}

allState = channelSettings.DefaultState;
allPreveState = allState;
}

private void OnGUI()
{
bool dirtySettings = false;
scrollViewVector = GUILayout.BeginScrollView(scrollViewVector);
EditorGUILayout.BeginVertical("Box");
bool allStateChanged = false;
allState = GUILayout.Toggle(allState, "All");

if (allState != allPreveState)
{
allPreveState = allState;
allStateChanged = true;
channelSettings.DefaultState = allState;
dirtySettings = true;
}

if (UnityDebugger.Debugger.Channels != null)
{
Dictionary<string, bool> toggleReturns = new Dictionary<string, bool>();
foreach (string channelName in UnityDebugger.Debugger.Channels.Keys.AsEnumerable())
{
toggleReturns.Add(channelName, GUILayout.Toggle(UnityDebugger.Debugger.Channels[channelName], channelName));
if (allStateChanged)
{
toggleReturns[channelName] = allState;
}
}

foreach (string channelName in toggleReturns.Keys.ToList())
{
UnityDebugger.Debugger.Channels[channelName] = toggleReturns[channelName];

if (channelSettings == null)
{
// We're in a weird state with no channelSettings, just bail 'til we get it back.
return;
}

if (!channelSettings.ChannelState.ContainsKey(channelName) && toggleReturns.ContainsKey(channelName))
{
bool theValueIWant = toggleReturns[channelName];
channelSettings.ChannelState.Add(channelName, theValueIWant);
dirtySettings = true;
}
else if (channelSettings.ChannelState[channelName] != toggleReturns[channelName])
{
channelSettings.ChannelState[channelName] = toggleReturns[channelName];
dirtySettings = true;
}
}
}

if (dirtySettings)
{
EditorUtility.SetDirty(channelSettings);
}

EditorGUILayout.EndVertical();
GUILayout.EndScrollView();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions Assets/Editor/SpriteToXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void ShowVersion1()

if (images.Length > 1)
{
Debug.ULogErrorChannel("SpriteToXML", "Place only one sprite in 'Resources/Editor/SpriteToXML'");
UnityDebugger.Debugger.LogError("SpriteToXML", "Place only one sprite in 'Resources/Editor/SpriteToXML'");
return;
}

Expand All @@ -191,16 +191,16 @@ private void ShowVersion1()

private void ExportSprites()
{
Debug.ULogChannel("SpriteToXML", "Files saved to: " + outputDirPath);
UnityDebugger.Debugger.Log("SpriteToXML", "Files saved to: " + outputDirPath);

foreach (string fn in filesInDir)
{
Debug.ULogChannel("SpriteToXML", "files in dir: " + fn);
UnityDebugger.Debugger.Log("SpriteToXML", "files in dir: " + fn);
}

foreach (Texture2D t in images)
{
Debug.ULogChannel("SpriteToXML", "Filename: " + t.name);
UnityDebugger.Debugger.Log("SpriteToXML", "Filename: " + t.name);
}

WriteXml();
Expand All @@ -210,7 +210,7 @@ private void WriteXml()
{
if (outputDirPath == string.Empty)
{
Debug.ULogErrorChannel("SpriteToXML", "Please select a folder");
UnityDebugger.Debugger.LogError("SpriteToXML", "Please select a folder");
return;
}

Expand Down Expand Up @@ -384,7 +384,7 @@ private void ShowVersion2()
if ((columnIndex == 0 && rowIndex == 0) && isMultipleSprite == true)
{
EditorUtility.DisplayDialog("Select proper Row/Column count", "Please select more than 1 Row/Column!", "OK");
Debug.ULogErrorChannel("SpriteToXML", "Please select more than 1 Row/Column");
UnityDebugger.Debugger.LogError("SpriteToXML", "Please select more than 1 Row/Column");
}
else
{
Expand Down Expand Up @@ -424,7 +424,7 @@ private void LoadImage(string filePath)
myTexture = imageTexture;
imageName = Path.GetFileNameWithoutExtension(filePath);
imageExt = Path.GetExtension(filePath);
Debug.ULogChannel("SpriteToXML", imageName + " Loaded");
UnityDebugger.Debugger.Log("SpriteToXML", imageName + " Loaded");
textureLoaded = true;
}
}
Expand Down Expand Up @@ -516,18 +516,18 @@ private void MoveImage(string filePath)
try
{
File.Replace(filePath, destPath, destPath + ".bak");
Debug.ULogWarningChannel("SpriteToXML", "Image already exsists, backing old one up to: " + destPath + ".bak");
UnityDebugger.Debugger.LogWarning("SpriteToXML", "Image already exsists, backing old one up to: " + destPath + ".bak");
}
catch (Exception ex)
{
Debug.ULogWarningChannel("SpriteToXML", ex.Message + " - " + imageName + imageExt + " not moved.");
UnityDebugger.Debugger.LogWarning("SpriteToXML", ex.Message + " - " + imageName + imageExt + " not moved.");
EditorUtility.DisplayDialog(imageName + imageExt + " not moved.", "The original and output directories cannot be the same!" + "\n\n" + "XML was still generated.", "OK");
}
}
else
{
File.Move(filePath, destPath);
Debug.ULogChannel("SpriteToXML", "Image moved to: " + destPath);
UnityDebugger.Debugger.Log("SpriteToXML", "Image moved to: " + destPath);
}

if (File.Exists(filePath + ".meta") && File.Exists(destPath + ".meta"))
Expand All @@ -538,7 +538,7 @@ private void MoveImage(string filePath)
}
catch (Exception ex)
{
Debug.ULogWarningChannel("SpriteToXML", ex.Message + " - " + imageName + imageExt + ".meta not moved.");
UnityDebugger.Debugger.LogWarning("SpriteToXML", ex.Message + " - " + imageName + imageExt + ".meta not moved.");
}
}
else
Expand Down
3 changes: 1 addition & 2 deletions Assets/Editor/UnitTests/Controllers/HeadlineGeneratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ public void SetUp()
gen = new HeadlineGenerator();
gen.UpdatedHeadline += StringPrinted;
stringPrinted = false;
Debug.IsLogEnabled = false;
}

public void StringPrinted(string headline)
{
Debug.Log(headline);
UnityDebugger.Debugger.Log(headline);
stringPrinted = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public static string PowerCellPress_StatusInfo(Furniture furniture)
[SetUp]
public void Init()
{
Debug.IsLogEnabled = false;
functions = new CSharpFunctions();
}

Expand Down
7 changes: 3 additions & 4 deletions Assets/Editor/UnitTests/Models/Functions/FunctionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function PowerGenerator_FuelInfo(furniture)
[SetUp]
public void Init()
{
Debug.IsLogEnabled = true;
csharpFunctions = new CSharpFunctions();
luaFunctions = new LuaFunctions();
}
Expand Down Expand Up @@ -76,9 +75,9 @@ public void CompareLUAvsCSharp()

sw2.Stop();

Debug.Log(string.Format("Iterations: {0}", cache.Count / 2));
Debug.Log(string.Format("CSharp calls: {0} ms", sw1.ElapsedMilliseconds));
Debug.Log(string.Format("LUA calls: {0} ms", sw2.ElapsedMilliseconds));
UnityDebugger.Debugger.Log(string.Format("Iterations: {0}", cache.Count / 2));
UnityDebugger.Debugger.Log(string.Format("CSharp calls: {0} ms", sw1.ElapsedMilliseconds));
UnityDebugger.Debugger.Log(string.Format("LUA calls: {0} ms", sw2.ElapsedMilliseconds));
}

private string ReplaceQuotes(string text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function test_func2()
[SetUp]
public void Init()
{
Debug.IsLogEnabled = false;
functions = new LuaFunctions();
}

Expand Down
11 changes: 5 additions & 6 deletions Assets/Editor/UnitTests/Models/ScheduledEventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ public class ScheduledEventTest
[SetUp]
public void Init()
{
Debug.IsLogEnabled = false;
callback = (evt) =>
{
Debug.ULogChannel("ScheduledEventTest", "Event {0} fired", evt.Name);
UnityDebugger.Debugger.LogFormat("ScheduledEventTest", "Event {0} fired", evt.Name);
didRun = true;
runCount++;
};
Expand All @@ -33,7 +32,7 @@ public void EventCreationTest()
{
ScheduledEvent evt = new ScheduledEvent(
"test",
(ev) => Debug.ULogChannel("ScheduledEventTest", "Event {0} fired", ev.Name),
(ev) => UnityDebugger.Debugger.LogFormat("ScheduledEventTest", "Event {0} fired", ev.Name),
3.0f,
true,
1);
Expand All @@ -45,7 +44,7 @@ public void EventCreationTest()
Assert.That(evt, Is.Not.EqualTo(evt2));

ScheduledEvent evt3 = new ScheduledEvent(
new ScheduledEvent("test", (ev) => Debug.ULogChannel("ScheduledEventTest", "Event {0} fired", ev.Name)),
new ScheduledEvent("test", (ev) => UnityDebugger.Debugger.LogFormat("ScheduledEventTest", "Event {0} fired", ev.Name)),
1.0f,
0.5f,
false,
Expand Down Expand Up @@ -197,7 +196,7 @@ public void LargeDeltaTimeEventRunTest()

ScheduledEvent evt = new ScheduledEvent(
"test",
(ev) => { tally++; Debug.ULogChannel("ScheduledEventTest", "Event {0} fired", ev.Name); },
(ev) => { tally++; UnityDebugger.Debugger.LogFormat("ScheduledEventTest", "Event {0} fired", ev.Name); },
3.0f,
true,
0);
Expand Down Expand Up @@ -245,7 +244,7 @@ public void ToJsonTest()
{
ScheduledEvent evt = new ScheduledEvent(
"test",
(ev) => Debug.ULogChannel("ScheduledEventTest", "Event {0} fired", ev.Name),
(ev) => UnityDebugger.Debugger.LogFormat("ScheduledEventTest", "Event {0} fired", ev.Name),
3.0f,
true,
1);
Expand Down
6 changes: 2 additions & 4 deletions Assets/Editor/UnitTests/Models/SchedulerEditorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ function ping_log_lua(event)
[SetUp]
public void Init()
{
Debug.IsLogEnabled = false;

if (FunctionsManager.ScheduledEvent == null)
{
new FunctionsManager();
Expand All @@ -46,14 +44,14 @@ public void Init()
new PrototypeManager();
}

PrototypeManager.ScheduledEvent.Add(new ScheduledEvent("ping_log", evt => Debug.ULogChannel("Scheduler", "Event {0} fired", evt.Name)));
PrototypeManager.ScheduledEvent.Add(new ScheduledEvent("ping_log", evt => UnityDebugger.Debugger.LogFormat("Scheduler", "Event {0} fired", evt.Name)));
PrototypeManager.ScheduledEvent.LoadPrototypes(XmlPrototypeString);

// The problem with unit testing singletons
///scheduler = Scheduler.Scheduler.Current;
scheduler = new Scheduler.Scheduler();

callback = evt => Debug.ULogChannel("SchedulerTest", "Event {0} fired", evt.Name);
callback = evt => UnityDebugger.Debugger.LogFormat("SchedulerTest", "Event {0} fired", evt.Name);
}

[Test]
Expand Down
1 change: 0 additions & 1 deletion Assets/Editor/UnitTests/Utilities/ParametersEditorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class ParametersEditorTest
[SetUp]
public void Init()
{
Debug.IsLogEnabled = false;
xmlTest1 = @"<Params>
<Param name='gas_limit' value='0.2' />
<Param name='gas_per_second' value='0.16' />
Expand Down
Binary file added Assets/Plugins/UnityDebugger.dll
Binary file not shown.
24 changes: 24 additions & 0 deletions Assets/Plugins/UnityDebugger.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d051088

Please sign in to comment.