Skip to content

Commit d39b9d1

Browse files
author
Chris Woerz
committed
RTLog cleanup and verbose mode, API uses verbose
1 parent dca125a commit d39b9d1

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

src/RemoteTech2/API/API.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static bool HasFlightComputer(Guid id)
1111
var satellite = RTCore.Instance.Satellites[id];
1212
if (satellite == null) return false;
1313
var hasFlightComputer = satellite.FlightComputer != null;
14-
RTLog.Notify("Flight: {0} HasFlightComputer: {1}", id, hasFlightComputer);
14+
RTLog.Verbose("Flight: {0} HasFlightComputer: {1}", id, hasFlightComputer);
1515
return hasFlightComputer;
1616
}
1717

@@ -23,7 +23,7 @@ public static void AddSanctionedPilot(Guid id, Action<FlightCtrlState> autopilot
2323
{
2424
if (spu.FlightComputer == null) continue;
2525
if (spu.FlightComputer.SanctionedPilots.Contains(autopilot)) continue;
26-
RTLog.Notify("Flight: {0} Adding Sanctioned Pilot", id);
26+
RTLog.Verbose("Flight: {0} Adding Sanctioned Pilot", id);
2727
spu.FlightComputer.SanctionedPilots.Add(autopilot);
2828
}
2929
}
@@ -35,7 +35,7 @@ public static void RemoveSanctionedPilot(Guid id, Action<FlightCtrlState> autopi
3535
foreach (var spu in satellite.SignalProcessors)
3636
{
3737
if (spu.FlightComputer == null) continue;
38-
RTLog.Notify("Flight: {0} Removing Sanctioned Pilot", id);
38+
RTLog.Verbose("Flight: {0} Removing Sanctioned Pilot", id);
3939
spu.FlightComputer.SanctionedPilots.Remove(autopilot);
4040
}
4141
}
@@ -44,15 +44,15 @@ public static bool HasAnyConnection(Guid id)
4444
{
4545
var satellite = RTCore.Instance.Satellites[id];
4646
var hasConnection = RTCore.Instance.Network[satellite].Any();
47-
RTLog.Notify("Flight: {0} Has Connection: {1}", id, hasConnection);
47+
RTLog.Verbose("Flight: {0} Has Connection: {1}", id, hasConnection);
4848
return hasConnection;
4949
}
5050

5151
public static bool HasConnectionToKSC(Guid id)
5252
{
5353
var satellite = RTCore.Instance.Satellites[id];
5454
var connectedToKerbin = RTCore.Instance.Network[satellite].Any(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid));
55-
RTLog.Notify("Flight: {0} Has Connection to Kerbin: {1}", id, connectedToKerbin);
55+
RTLog.Verbose("Flight: {0} Has Connection to Kerbin: {1}", id, connectedToKerbin);
5656
return connectedToKerbin;
5757
}
5858

@@ -61,7 +61,7 @@ public static double GetShortestSignalDelay(Guid id)
6161
var satellite = RTCore.Instance.Satellites[id];
6262
if (!RTCore.Instance.Network[satellite].Any()) return Double.PositiveInfinity;
6363
var shortestDelay = RTCore.Instance.Network[satellite].Min().Delay;
64-
RTLog.Notify("Flight: Shortest signal delay from {0} to {1}", id, shortestDelay);
64+
RTLog.Verbose("Flight: Shortest signal delay from {0} to {1}", id, shortestDelay);
6565
return shortestDelay;
6666
}
6767

@@ -70,7 +70,7 @@ public static double GetSignalDelayToKSC(Guid id)
7070
var satellite = RTCore.Instance.Satellites[id];
7171
if (!RTCore.Instance.Network[satellite].Any(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid))) return Double.PositiveInfinity;
7272
var signalDelaytoKerbin = RTCore.Instance.Network[satellite].Where(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid)).Min().Delay;
73-
RTLog.Notify("Connection from {0} to Kerbin Delay: {1}", id, signalDelaytoKerbin);
73+
RTLog.Verbose("Connection from {0} to Kerbin Delay: {1}", id, signalDelaytoKerbin);
7474
return signalDelaytoKerbin;
7575
}
7676

@@ -86,7 +86,7 @@ public static double GetSignalDelayToSatellite(Guid a, Guid b)
8686

8787
var path = NetworkPathfinder.Solve(satelliteA, satelliteB, neighbors, cost, heuristic);
8888
var delayBetween = path.Delay;
89-
RTLog.Notify("Connection from {0} to {1} Delay: {2}", a, b, delayBetween);
89+
RTLog.Verbose("Connection from {0} to {1} Delay: {2}", a, b, delayBetween);
9090
return delayBetween;
9191
}
9292
}

src/RemoteTech2/RTLog.cs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,51 @@
1-
using System;
1+
using System.Collections.Generic;
22
using System.Linq;
3-
using System.Text;
4-
using System.Collections.Generic;
5-
using UnityEngine;
6-
using System.Diagnostics;
73

84
namespace RemoteTech
95
{
106
public static class RTLog
117
{
12-
[Conditional("DEBUG")]
13-
public static void Debug(String message)
14-
{
15-
UnityEngine.Debug.Log("RemoteTech: " + message);
16-
}
8+
private static readonly bool verboseLogging;
179

18-
[Conditional("DEBUG")]
19-
public static void Debug(String message, params System.Object[] param)
10+
static RTLog()
2011
{
21-
UnityEngine.Debug.Log(String.Format("RemoteTech: " + message, param));
12+
verboseLogging = GameSettings.VERBOSE_DEBUG_LOG;
2213
}
2314

24-
[Conditional("DEBUG")]
25-
public static void Debug(String message, params UnityEngine.Object[] param)
15+
public static void Notify(string message)
2616
{
27-
UnityEngine.Debug.Log(String.Format("RemoteTech: " + message, param));
17+
UnityEngine.Debug.Log("RemoteTech: " + message);
2818
}
2919

30-
public static void Notify(String message)
20+
public static void Notify(string message, params UnityEngine.Object[] param)
3121
{
32-
UnityEngine.Debug.Log("RemoteTech: " + message);
22+
UnityEngine.Debug.Log(string.Format("RemoteTech: " + message, param));
3323
}
3424

35-
public static void Notify(String message, params UnityEngine.Object[] param)
25+
public static void Notify(string message, params object[] param)
3626
{
37-
UnityEngine.Debug.Log(String.Format("RemoteTech: " + message, param));
27+
UnityEngine.Debug.Log(string.Format("RemoteTech: " + message, param));
3828
}
3929

40-
public static void Notify(String message, params System.Object[] param)
30+
public static void Verbose(string message, params object[] param)
4131
{
42-
UnityEngine.Debug.Log(String.Format("RemoteTech: " + message, param));
32+
if (verboseLogging)
33+
{
34+
Notify(message, param);
35+
}
4336
}
4437

45-
public static string ToDebugString<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)
38+
public static void Verbose(string message, params UnityEngine.Object[] param)
4639
{
47-
return "{" +
48-
string.Join(",",
49-
dictionary.Select(kv => kv.Key.ToString() + "=" + kv.Value.ToString())
50-
.ToArray()) + "}";
40+
if (verboseLogging)
41+
{
42+
Notify(message, param);
43+
}
5144
}
45+
}
5246

47+
public static class LoggingExtenstions
48+
{
5349
public static string ToDebugString<T>(this List<T> list)
5450
{
5551
return "{" + string.Join(",", list.Select(x => x.ToString()).ToArray()) + "}";

0 commit comments

Comments
 (0)