Skip to content

Commit

Permalink
Merge pull request #1534 from WEKIT-ECS/debug-log-tweaks
Browse files Browse the repository at this point in the history
Debug Log with Importance Levels
  • Loading branch information
BenediktHensen authored Aug 10, 2023
2 parents f2c6903 + a8535e2 commit c3b00ed
Show file tree
Hide file tree
Showing 87 changed files with 317 additions and 233 deletions.
2 changes: 1 addition & 1 deletion Assets/MirageXR/Common/Scripts/CalibrationTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Initialization(float animationTime)

if (imageTarget == null)
{
AppLog.LogError("Can't find IImageTarget");
Debug.LogError("Can't find IImageTarget");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ private async Task<bool> InitAsync()
{
if (string.IsNullOrEmpty(_content.url))
{
AppLog.LogError("Content URL not provided.");
Debug.LogError("Content URL not provided.");
return false;
}

if (!SetParent(_content))
{
AppLog.LogError("Couldn't set the parent.");
Debug.LogError("Couldn't set the parent.");
return false;
}

Expand All @@ -53,7 +53,7 @@ private async Task<bool> InitAsync()

if (imageTarget == null)
{
AppLog.LogError("Can't add image target");
Debug.LogError("Can't add image target");
return false;
}
}
Expand All @@ -71,7 +71,7 @@ private async Task<ImageTargetBase> LoadImage()

if (!texture.LoadImage(byteArray))
{
AppLog.LogError($"Can't load image. path: {imagePath}");
Debug.LogError($"Can't load image. path: {imagePath}");
return null;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ private void MoveDetectableToImage(Transform targetHolder)
}
else
{
AppLog.LogError($"Can't find detectable {detectable.id}");
Debug.LogError($"Can't find detectable {detectable.id}");
}
}

Expand All @@ -118,7 +118,7 @@ public void MoveDetectableBack()
}
else
{
AppLog.LogError($"Can't find detectable {detectable.id}");
Debug.LogError($"Can't find detectable {detectable.id}");
}
}

Expand All @@ -139,7 +139,7 @@ private void OnDestroy()
}
catch (Exception e)
{
AppLog.LogError("Error when destroying image marker controller" + e.ToString());
Debug.LogError("Error when destroying image marker controller" + e.ToString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public static async Task CreateObjects()
// If workplace has anchors which have not been calibrated...
if (workplaceManager.calibrationPairs.Count > 0 && !UiManager.Instance.IsCalibrated)
{
AppLog.LogWarning("Workplace has uncalibrated anchors. Please re-run the calibration");
Debug.LogWarning("Workplace has uncalibrated anchors. Please re-run the calibration");
}

AppLog.LogInfo("********** EventManager.WorkplaceLoaded");
Debug.Log("********** EventManager.WorkplaceLoaded");
// SUGGESTION Use a different event here that symbolizes the end of the view update by the model
EventManager.WorkplaceLoaded();
}
Expand Down
8 changes: 8 additions & 0 deletions Assets/MirageXR/Common/Scripts/Logger.meta

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

66 changes: 66 additions & 0 deletions Assets/MirageXR/Common/Scripts/Logger/Debug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using i5.Toolkit.Core.VerboseLogging;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Debug : UnityEngine.Debug
{
public static LogLevel MinimumLogLevel
{
get => AppLog.MinimumLogLevel;
set
{
AppLog.MinimumLogLevel = value;
}
}

public static void LogCritical(object message, Object context)
{
AppLog.LogCritical(message.ToString(), context);
}

public static new void LogError(object message)
{
AppLog.LogError(message.ToString());
}

public static new void LogError(object message, Object context)
{
AppLog.LogError(message.ToString(), context);
}

public static new void LogWarning(object message)
{
AppLog.LogWarning(message.ToString());
}

public static new void LogWarning(object message, Object context)
{
AppLog.LogWarning(message.ToString(), context);
}

public static new void Log(object message)
{
AppLog.LogInfo(message.ToString());
}

public static new void Log(object message, Object context)
{
AppLog.LogInfo(message.ToString(), context);
}

public static void LogInfo(object message, Object context = null)
{
AppLog.LogInfo(message.ToString(), context);
}

public static void LogDebug(object message, Object context = null)
{
AppLog.LogDebug(message.ToString(), context);
}

public static void LogTrace(object message, Object context = null)
{
AppLog.LogTrace(message.ToString(), context);
}
}
11 changes: 11 additions & 0 deletions Assets/MirageXR/Common/Scripts/Logger/Debug.cs.meta

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

8 changes: 4 additions & 4 deletions Assets/MirageXR/Common/Scripts/Managers/CalibrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ private async Task EnableCalibrationAsync(bool isRecalibration = false)
var value = await CreateCalibrationTool(isRecalibration);
if (!value)
{
AppLog.LogError("Unable to create imageTarget");
Debug.LogError("Unable to create imageTarget");
return;
}
}

if (!InitCalibrationTool(_imageTarget))
{
AppLog.LogError("Unable to create calibrationTool");
Debug.LogError("Unable to create calibrationTool");
return;
}

Expand All @@ -136,7 +136,7 @@ private async Task<bool> CreateCalibrationTool(bool isRecalibration = false)
}
catch (Exception e)
{
AppLog.LogError(e.ToString());
Debug.LogError(e.ToString());
return false;
}
finally
Expand All @@ -150,7 +150,7 @@ private bool InitCalibrationTool(IImageTarget imageTarget)
_calibrationTool = imageTarget.targetObject.GetComponent<CalibrationTool>();
if (!_calibrationTool)
{
AppLog.LogError($"{nameof(CalibrationTool)} cannot be found");
Debug.LogError($"{nameof(CalibrationTool)} cannot be found");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/MirageXR/Common/Scripts/Redesign/LocalFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static bool TryGetPassword(string key, out string username, out string pa
}
catch (Exception e)
{
AppLog.LogError(e.ToString());
Debug.LogError(e.ToString());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ private void OnDisable()
protected override void RegisterServices()
{
#if UNITY_EDITOR
AppLog.MinimumLogLevel = LogLevel.TRACE;
Debug.MinimumLogLevel = LogLevel.TRACE;
#else
AppLog.MinimumLogLevel = LogLevel.INFO;
Debug.MinimumLogLevel = LogLevel.INFO;
#endif

ServiceManager.RegisterService(new WorldAnchorService());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Threading;
using System.IO;
using System.Diagnostics;
using Debug = UnityEngine.Debug;
using System.Net;
using System.Threading.Tasks;

Expand Down
4 changes: 2 additions & 2 deletions Assets/MirageXR/Common/Scripts/Sketchfab/Sketchfab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private static ModelPreviewItem CreateUserPreview(SketchfabCollection sketchfabC
}
catch (Exception e)
{
AppLog.LogError(e.ToString());
Debug.LogError(e.ToString());
return (false, null);
}
}
Expand Down Expand Up @@ -268,7 +268,7 @@ private static ModelPreviewItem CreateUserPreview(SketchfabCollection sketchfabC
}
catch (Exception e)
{
AppLog.LogError(e.ToString());
Debug.LogError(e.ToString());
return (false, null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void Start()
}
}

AppLog.LogTrace("Action list menu start called");
Debug.LogTrace("Action list menu start called");
EventManager.OnInitUi += Init;
EventManager.OnActivateAction += OnActivateAction;
EventManager.OnDeactivateAction += OnDeactivateAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void DoUploadProcess()

public void OnEditToggleChanged(bool value)
{
AppLog.LogDebug("Toggle changed " + value);
Debug.LogDebug("Toggle changed " + value);
if (RootObject.Instance.activityManager != null)
{
RootObject.Instance.activityManager.EditModeActive = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private void OnEnable()

private void OnTextUpdated(string value)
{
AppLog.LogDebug($"Text updated: {value}");
Debug.LogDebug($"Text updated: {value}");
if (string.IsNullOrEmpty(value))
{
_sessionListView.SetAllItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public async void OnActivitySelected()
// show loading label
Loading.Instance.LoadingVisibility(true);

AppLog.LogInfo("Playing activity...");
Debug.LogInfo("Playing activity...");
Play();
}
}

private async Task DownloadAsync()
{
AppLog.LogInfo("Downloading session...");
Debug.LogInfo("Downloading session...");
// reset any error
_selectedListViewItem.Content.HasError = false;
// indicate that the system is working
Expand All @@ -42,7 +42,7 @@ private async Task DownloadAsync()

bool success;
Session arlemFile = _selectedListViewItem.Content.Session;
AppLog.LogInfo($"Downloading from {arlemFile.contextid}/{arlemFile.component}/{arlemFile.filearea}/{arlemFile.itemid}/{arlemFile.filename}");
Debug.LogInfo($"Downloading from {arlemFile.contextid}/{arlemFile.component}/{arlemFile.filearea}/{arlemFile.itemid}/{arlemFile.filename}");
using (SessionDownloader downloader = new SessionDownloader($"{DBManager.domain}/pluginfile.php/{arlemFile.contextid}/{arlemFile.component}/{arlemFile.filearea}/{arlemFile.itemid}/{arlemFile.filename}", arlemFile.sessionid + ".zip"))
{
success = await downloader.DownloadZipFileAsync();
Expand All @@ -55,7 +55,7 @@ private async Task DownloadAsync()
}
catch (Exception e)
{
AppLog.LogException(e);
Debug.LogException(e);
success = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<bool> DownloadZipFileAsync()
using (UnityWebRequest req = new UnityWebRequest(_downloadUrl))
{
req.method = UnityWebRequest.kHttpVerbGET;
AppLog.LogInfo($"Downloading zip file to " + _zipFilePath);
Debug.LogInfo($"Downloading zip file to " + _zipFilePath);
DownloadHandlerFile downloadHandler = new DownloadHandlerFile(_zipFilePath) { removeFileOnAbort = true };
req.downloadHandler = downloadHandler;
await req.SendWebRequest();
Expand All @@ -38,8 +38,8 @@ public async Task<bool> DownloadZipFileAsync()

public async Task UnzipFileAsync()
{
AppLog.LogDebug($"Application persistent data path is {Application.persistentDataPath}");
AppLog.LogInfo($"Unzipping zip file from {_zipFilePath} to {_targetFolder}");
Debug.LogDebug($"Application persistent data path is {Application.persistentDataPath}");
Debug.LogInfo($"Unzipping zip file from {_zipFilePath} to {_targetFolder}");
using (Stream stream = new FileStream(_zipFilePath, FileMode.Open))
{
await ZipUtilities.ExtractZipFileAsync(stream, _targetFolder);
Expand All @@ -48,10 +48,10 @@ public async Task UnzipFileAsync()

public void Dispose()
{
AppLog.LogTrace("Disposing session downloader");
Debug.LogTrace("Disposing session downloader");
if (File.Exists(_zipFilePath))
{
AppLog.LogDebug($"Clean up: Deleting zip file at {_zipFilePath}");
Debug.LogDebug($"Clean up: Deleting zip file at {_zipFilePath}");
File.Delete(_zipFilePath);
}
}
Expand Down
Loading

0 comments on commit c3b00ed

Please sign in to comment.