Unify logging

And add helpful tags to everything
pull/477/head
blowfish 5 years ago
parent ddb79541f5
commit a453ed89eb

@ -31,7 +31,7 @@ namespace Restock
if (string.IsNullOrEmpty(serializedNode)) if (string.IsNullOrEmpty(serializedNode))
{ {
Debug.LogError("Serialized node is null or empty!"); this.LogError("Serialized node is null or empty!");
yield break; yield break;
} }
@ -41,7 +41,7 @@ namespace Restock
if (fairingModule == null) if (fairingModule == null)
{ {
Debug.LogError("No fairing module found on part!"); this.LogError("No fairing module found on part!");
yield break; yield break;
} }
@ -56,7 +56,7 @@ namespace Restock
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.LogException(new Exception($"[{nameof(ModuleRestockModifyFairingMaterials)}] cannot parse node as material modifier: \n{node2.ToString()}\n", ex)); this.LogException($"cannot parse node as material modifier: \n{node2.ToString()}\n", ex);
continue; continue;
} }

@ -29,7 +29,7 @@ namespace Restock
} }
else else
{ {
Debug.LogError($"Can't find shader {newShaderName}"); this.LogError($"Can't find shader {newShaderName}");
continue; continue;
} }
@ -46,7 +46,7 @@ namespace Restock
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.LogException(new Exception($"[{nameof(ModuleRestockModifyMaterials)}] cannot parse node as material modifier: \n{node3.ToString()}\n", ex)); this.LogException($"cannot parse node as material modifier: \n{node3.ToString()}\n", ex);
continue; continue;
} }
@ -74,7 +74,7 @@ namespace Restock
if (modelTransforms.Length == 0) if (modelTransforms.Length == 0)
{ {
Debug.LogError($"Couldn't find transform named '{value.name}' on part"); this.LogError($"Couldn't find transform named '{value.name}' on part");
continue; continue;
} }
@ -84,7 +84,7 @@ namespace Restock
Renderer renderer = transform.GetComponent<Renderer>(); Renderer renderer = transform.GetComponent<Renderer>();
if (renderer == null) if (renderer == null)
Debug.LogError($"No renderer found on transform '{transform.name}'"); this.LogError($"No renderer found on transform '{transform.name}'");
else else
transformRenderers.Add(renderer); transformRenderers.Add(renderer);
} }
@ -98,7 +98,7 @@ namespace Restock
if (modelTransforms.Length == 0) if (modelTransforms.Length == 0)
{ {
Debug.LogError($"Couldn't find transform named '{value.name}' on part"); this.LogError($"Couldn't find transform named '{value.name}' on part");
continue; continue;
} }
@ -107,7 +107,7 @@ namespace Restock
Renderer[] transformRenderers = transform.GetComponentsInChildren<Renderer>(); Renderer[] transformRenderers = transform.GetComponentsInChildren<Renderer>();
if (transformRenderers.Length == 0) if (transformRenderers.Length == 0)
Debug.LogError($"No renderers found on transform '{transform.name}' or its children"); this.LogError($"No renderers found on transform '{transform.name}' or its children");
else else
renderers.Concat(transform.GetComponentsInChildren<Renderer>()); renderers.Concat(transform.GetComponentsInChildren<Renderer>());
} }
@ -121,7 +121,7 @@ namespace Restock
Transform modelTransform = part.partTransform.Find("model"); Transform modelTransform = part.partTransform.Find("model");
if (modelTransform == null) if (modelTransform == null)
Debug.LogError("Couldn't find model transform"); this.LogError("Couldn't find model transform");
else else
renderers = modelTransform.GetComponentsInChildren<Renderer>(); renderers = modelTransform.GetComponentsInChildren<Renderer>();
} }

@ -0,0 +1,16 @@
using System;
using UnityEngine;
namespace Restock
{
public static class PartModuleExtensions
{
public static void Log(this PartModule module, string message) => Debug.Log(FormatMessage(module, message));
public static void LogWarning(this PartModule module, string message) => Debug.LogWarning(FormatMessage(module, message));
public static void LogError(this PartModule module, string message) => Debug.LogError(FormatMessage(module, message));
public static void LogException(this PartModule module, string message, Exception exception) => Debug.LogException(new Exception(FormatMessage(module, message), exception));
private static string FormatMessage(PartModule module, string message) => $"[{GetPartName(module.part)} {module.GetType()}] {message}";
private static string GetPartName(Part part) => part.partInfo?.name ?? part.name;
}
}
Loading…
Cancel
Save