Skip to content

Commit fd8b547

Browse files
committed
Add Async Debug Logger
1 parent 7502082 commit fd8b547

File tree

11 files changed

+247
-175
lines changed

11 files changed

+247
-175
lines changed

Assets/UnityEventTimeline/Runtime/EventTimeline.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
using UnityEngine.SceneManagement;
1313
using UnityEventTimeline.Internal;
1414

15+
#if __EVENTTIMELINE_DEBUG || __EVENTTIMELINE_DEBUG_VERBOSE
16+
using UnityEventTimeline.Internal.Logger;
17+
#endif
18+
1519
namespace UnityEventTimeline
1620
{
1721
/// <summary>
@@ -62,7 +66,7 @@ public static EventTimeline Instance
6266
lock (SingletonLock)
6367
{
6468
#if __EVENTTIMELINE_DEBUG_VERBOSE
65-
Debug.Log("[EventTimeline] Creating new instance");
69+
AsyncLogger.Log("[EventTimeline] Creating new instance");
6670
#endif
6771
var go = new GameObject(nameof(EventTimeline));
6872
_instance = go.AddComponent<EventTimeline>();
@@ -103,7 +107,7 @@ protected override void Awake()
103107
if (_instance is not null && _instance != this)
104108
{
105109
#if __EVENTTIMELINE_DEBUG
106-
Debug.LogWarning("[EventTimeline] Duplicate instance detected, destroying GameObject");
110+
AsyncLogger.LogWarning("[EventTimeline] Duplicate instance detected, destroying GameObject");
107111
#endif
108112

109113
Destroy(gameObject);
@@ -116,7 +120,7 @@ protected override void Awake()
116120
DontDestroyOnLoad(gameObject);
117121

118122
#if __EVENTTIMELINE_DEBUG_VERBOSE
119-
Debug.Log("[EventTimeline] Instance initialized in Awake");
123+
AsyncLogger.Log("[EventTimeline] Instance initialized in Awake");
120124
#endif
121125
}
122126
}
@@ -159,7 +163,7 @@ protected override void OnDestroy()
159163
if (_instance == this)
160164
{
161165
#if __EVENTTIMELINE_DEBUG_VERBOSE
162-
Debug.Log("[EventTimeline] Clearing singleton instance");
166+
AsyncLogger.Log("[EventTimeline] Clearing singleton instance");
163167
#endif
164168
_instance = null;
165169
}
@@ -176,13 +180,13 @@ protected override void OnDestroy()
176180
private void HandleSceneUnloaded(Scene scene)
177181
{
178182
#if __EVENTTIMELINE_DEBUG_VERBOSE
179-
Debug.Log($"[EventTimeline] Scene unloaded: {scene.name}");
183+
AsyncLogger.LogFormat("[EventTimeline] Scene unloaded: {0}", scene.name);
180184
#endif
181185

182186
OptimizeMemory();
183187

184188
#if __EVENTTIMELINE_DEBUG_VERBOSE
185-
Debug.Log("[EventTimeline] Memory optimization completed after scene unload");
189+
AsyncLogger.Log("[EventTimeline] Memory optimization completed after scene unload");
186190
#endif
187191
}
188192
}

Assets/UnityEventTimeline/Runtime/Internal/EventQueue/EventPriorityQueue.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
using System.Linq;
1515

1616
#if __EVENTTIMELINE_DEBUG || __EVENTTIMELINE_DEBUG_VERBOSE
17-
using UnityEngine;
17+
using UnityEventTimeline.Internal.Logger;
1818
#endif
1919

2020
namespace UnityEventTimeline.Internal.EventQueue
@@ -180,7 +180,7 @@ public EventPriorityQueue(int capacity = DefaultCapacity)
180180
_heap = new List<T>(capacity > 0 ? capacity : DefaultCapacity);
181181

182182
#if __EVENTTIMELINE_DEBUG_VERBOSE
183-
Debug.Log($"[EventPriorityQueue] Initialized with capacity: {capacity}, DefaultCapacity: {DefaultCapacity}");
183+
AsyncLogger.LogFormat("[EventPriorityQueue] Initialized with capacity: {0}, DefaultCapacity: {1}", capacity, DefaultCapacity);
184184
#endif
185185
}
186186

@@ -200,13 +200,13 @@ public bool TryPeek([NotNullWhen(true)] out T? item)
200200
{
201201
item = _heap[0];
202202
#if __EVENTTIMELINE_DEBUG_VERBOSE
203-
Debug.Log($"[EventPriorityQueue] Peeked item of type {item.GetType().Name}");
203+
AsyncLogger.LogFormat("[EventPriorityQueue] Peeked item of type {0}", item.GetType().Name);
204204
#endif
205205
return true;
206206
}
207207

208208
#if __EVENTTIMELINE_DEBUG
209-
Debug.LogWarning("[EventPriorityQueue] TryPeek failed - queue is empty");
209+
AsyncLogger.LogWarning("[EventPriorityQueue] TryPeek failed - queue is empty");
210210
#endif
211211
item = null;
212212
return false;
@@ -227,13 +227,13 @@ public void Enqueue(T item)
227227
{
228228
#if __EVENTTIMELINE_DEBUG_VERBOSE
229229
var initialCount = _heap.Count;
230-
Debug.Log($"[EventPriorityQueue] Enqueuing item of type {item.GetType().Name}. Current queue size: {initialCount}");
230+
AsyncLogger.LogFormat("[EventPriorityQueue] Enqueuing item of type {0}. Current queue size: {1}", item.GetType().Name, initialCount);
231231
#endif
232232
_heap.Add(item);
233233
HeapifyUp(_heap.Count - 1);
234234

235235
#if __EVENTTIMELINE_DEBUG_VERBOSE
236-
Debug.Log($"[EventPriorityQueue] Item enqueued successfully. New queue size: {_heap.Count}");
236+
AsyncLogger.LogFormat("[EventPriorityQueue] Item enqueued successfully. New queue size: {0}", _heap.Count);
237237
#endif
238238
}
239239
}
@@ -252,7 +252,7 @@ public void EnqueueRange(IEnumerable<T> items)
252252
{
253253
#if __EVENTTIMELINE_DEBUG_VERBOSE
254254
var initialCount = _heap.Count;
255-
Debug.Log($"[EventPriorityQueue] Beginning bulk enqueue operation. Current queue size: {initialCount}");
255+
AsyncLogger.LogFormat("[EventPriorityQueue] Beginning bulk enqueue operation. Current queue size: {0}", initialCount);
256256
#endif
257257
_heap.AddRange(items);
258258

@@ -264,7 +264,7 @@ public void EnqueueRange(IEnumerable<T> items)
264264

265265
#if __EVENTTIMELINE_DEBUG_VERBOSE
266266
var itemsAdded = _heap.Count - initialCount;
267-
Debug.Log($"[EventPriorityQueue] Bulk enqueue completed. Added {itemsAdded} items. New queue size: {_heap.Count}");
267+
AsyncLogger.LogFormat("[EventPriorityQueue] Bulk enqueue completed. Added {0} items. New queue size: {1}", itemsAdded, _heap.Count);
268268
#endif
269269
}
270270
}
@@ -284,7 +284,7 @@ public IEnumerable<T> DequeueRange(int count)
284284
if (count <= 0)
285285
{
286286
#if __EVENTTIMELINE_DEBUG
287-
Debug.LogWarning("[EventPriorityQueue] DequeueRange called with count <= 0, returning empty array");
287+
AsyncLogger.LogWarning("[EventPriorityQueue] DequeueRange called with count <= 0, returning empty array");
288288
#endif
289289
return Array.Empty<T>();
290290
}
@@ -294,7 +294,7 @@ public IEnumerable<T> DequeueRange(int count)
294294
{
295295
#if __EVENTTIMELINE_DEBUG_VERBOSE
296296
var initialCount = _heap.Count;
297-
Debug.Log($"[EventPriorityQueue] Beginning DequeueRange operation. Requested: {count}, Available: {initialCount}");
297+
AsyncLogger.LogFormat("[EventPriorityQueue] Beginning DequeueRange operation. Requested: {0}, Available: {1}", count, initialCount);
298298
#endif
299299

300300
var resultSize = Math.Min(count, _heap.Count);
@@ -304,7 +304,7 @@ public IEnumerable<T> DequeueRange(int count)
304304
if (resultSize > _heap.Count / 2)
305305
{
306306
#if __EVENTTIMELINE_DEBUG_VERBOSE
307-
Debug.Log($"[EventPriorityQueue] Using bulk dequeue optimization for {resultSize} items");
307+
AsyncLogger.LogFormat("[EventPriorityQueue] Using bulk dequeue optimization for {0} items", resultSize);
308308
#endif
309309
result.AddRange(_heap.OrderBy(x => x));
310310
_heap.Clear();
@@ -318,7 +318,7 @@ public IEnumerable<T> DequeueRange(int count)
318318
}
319319

320320
#if __EVENTTIMELINE_DEBUG_VERBOSE
321-
Debug.Log($"[EventPriorityQueue] DequeueRange completed. Dequeued: {result.Count}, Remaining: {_heap.Count}");
321+
AsyncLogger.LogFormat("[EventPriorityQueue] DequeueRange completed. Dequeued: {0}, Remaining: {1}", result.Count, _heap.Count);
322322
#endif
323323
}
324324

@@ -338,13 +338,13 @@ public void Clear()
338338
{
339339
#if __EVENTTIMELINE_DEBUG_VERBOSE
340340
var clearedCount = _heap.Count;
341-
Debug.Log($"[EventPriorityQueue] Clearing queue. Items to be cleared: {clearedCount}");
341+
AsyncLogger.LogFormat("[EventPriorityQueue] Clearing queue. Items to be cleared: {0}", clearedCount);
342342
#endif
343343

344344
_heap.Clear();
345345

346346
#if __EVENTTIMELINE_DEBUG_VERBOSE
347-
Debug.Log("[EventPriorityQueue] Queue cleared successfully");
347+
AsyncLogger.Log("[EventPriorityQueue] Queue cleared successfully");
348348
#endif
349349
}
350350
}
@@ -362,13 +362,13 @@ public void TrimExcess()
362362
{
363363
#if __EVENTTIMELINE_DEBUG_VERBOSE
364364
var initialCapacity = _heap.Capacity;
365-
Debug.Log($"[EventPriorityQueue] Beginning TrimExcess. Current capacity: {initialCapacity}, Count: {_heap.Count}");
365+
AsyncLogger.LogFormat("[EventPriorityQueue] Beginning TrimExcess. Current capacity: {0}, Count: {1}", initialCapacity, _heap.Count);
366366
#endif
367367

368368
_heap.TrimExcess();
369369

370370
#if __EVENTTIMELINE_DEBUG_VERBOSE
371-
Debug.Log($"[EventPriorityQueue] TrimExcess completed. New capacity: {_heap.Capacity}");
371+
AsyncLogger.LogFormat("[EventPriorityQueue] TrimExcess completed. New capacity: {0}", _heap.Capacity);
372372
#endif
373373
}
374374
}
@@ -388,7 +388,7 @@ public bool Contains(T item)
388388
{
389389
var contains = _heap.Contains(item);
390390
#if __EVENTTIMELINE_DEBUG_VERBOSE
391-
Debug.Log($"[EventPriorityQueue] Contains check for item of type {item.GetType().Name}: {contains}");
391+
AsyncLogger.LogFormat("[EventPriorityQueue] Contains check for item of type {0}: {1}", item.GetType().Name, contains);
392392
#endif
393393
return contains;
394394
}
@@ -409,14 +409,14 @@ public bool TryRemove(T item)
409409
lock (_heapLock)
410410
{
411411
#if __EVENTTIMELINE_DEBUG_VERBOSE
412-
Debug.Log($"[EventPriorityQueue] Attempting to remove item of type {item.GetType().Name}");
412+
AsyncLogger.LogFormat("[EventPriorityQueue] Attempting to remove item of type {0}", item.GetType().Name);
413413
#endif
414414

415415
var index = _heap.IndexOf(item);
416416
if (index == -1)
417417
{
418418
#if __EVENTTIMELINE_DEBUG
419-
Debug.LogWarning("[EventPriorityQueue] Item not found in queue");
419+
AsyncLogger.LogWarning("[EventPriorityQueue] Item not found in queue");
420420
#endif
421421
return false;
422422
}
@@ -426,7 +426,7 @@ public bool TryRemove(T item)
426426
{
427427
_heap.RemoveAt(index);
428428
#if __EVENTTIMELINE_DEBUG_VERBOSE
429-
Debug.Log("[EventPriorityQueue] Removed last item in queue");
429+
AsyncLogger.Log("[EventPriorityQueue] Removed last item in queue");
430430
#endif
431431
return true;
432432
}
@@ -443,7 +443,7 @@ public bool TryRemove(T item)
443443
HeapifyDown(index);
444444

445445
#if __EVENTTIMELINE_DEBUG_VERBOSE
446-
Debug.Log($"[EventPriorityQueue] Item removed successfully. New queue size: {_heap.Count}");
446+
AsyncLogger.LogFormat("[EventPriorityQueue] Item removed successfully. New queue size: {0}", _heap.Count);
447447
#endif
448448

449449
return true;
@@ -463,7 +463,7 @@ public bool TryRemove(T item)
463463
private T DequeueInternal()
464464
{
465465
#if __EVENTTIMELINE_DEBUG_VERBOSE
466-
Debug.Log("[EventPriorityQueue] Beginning internal dequeue operation");
466+
AsyncLogger.Log("[EventPriorityQueue] Beginning internal dequeue operation");
467467
#endif
468468

469469
var result = _heap[0];
@@ -477,7 +477,7 @@ private T DequeueInternal()
477477
}
478478

479479
#if __EVENTTIMELINE_DEBUG_VERBOSE
480-
Debug.Log($"[EventPriorityQueue] Internal dequeue completed. Dequeued item of type {result.GetType().Name}");
480+
AsyncLogger.LogFormat("[EventPriorityQueue] Internal dequeue completed. Dequeued item of type {0}", result.GetType().Name);
481481
#endif
482482

483483
return result;
@@ -496,7 +496,7 @@ private T DequeueInternal()
496496
private void HeapifyUp(int index)
497497
{
498498
#if __EVENTTIMELINE_DEBUG_VERBOSE
499-
Debug.Log($"[EventPriorityQueue] Beginning HeapifyUp from index {index}");
499+
AsyncLogger.LogFormat("[EventPriorityQueue] Beginning HeapifyUp from index {0}", index);
500500
var initialIndex = index;
501501
#endif
502502

@@ -521,7 +521,7 @@ private void HeapifyUp(int index)
521521
#if __EVENTTIMELINE_DEBUG_VERBOSE
522522
if (index != initialIndex)
523523
{
524-
Debug.Log($"[EventPriorityQueue] HeapifyUp moved item from index {initialIndex} to {index}");
524+
AsyncLogger.LogFormat("[EventPriorityQueue] HeapifyUp moved item from index {0} to {1}", initialIndex, index);
525525
}
526526
#endif
527527
}
@@ -540,7 +540,7 @@ private void HeapifyUp(int index)
540540
private void HeapifyDown(int index)
541541
{
542542
#if __EVENTTIMELINE_DEBUG_VERBOSE
543-
Debug.Log($"[EventPriorityQueue] Beginning HeapifyDown from index {index}");
543+
AsyncLogger.LogFormat("[EventPriorityQueue] Beginning HeapifyDown from index {0}", index);
544544
var initialIndex = index;
545545
var swaps = 0;
546546
#endif
@@ -583,7 +583,7 @@ private void HeapifyDown(int index)
583583
#if __EVENTTIMELINE_DEBUG_VERBOSE
584584
if (swaps > 0)
585585
{
586-
Debug.Log($"[EventPriorityQueue] HeapifyDown moved item from index {initialIndex} to {index} with {swaps} swaps");
586+
AsyncLogger.LogFormat("[EventPriorityQueue] HeapifyDown moved item from index {0} to {1} with {2} swaps", initialIndex, index, swaps);
587587
}
588588
#endif
589589
}

Assets/UnityEventTimeline/Runtime/Internal/EventTimelineBase.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
using System.Threading;
1313
using UnityEngine;
1414

15+
#if __EVENTTIMELINE_DEBUG || __EVENTTIMELINE_DEBUG_VERBOSE
16+
using UnityEventTimeline.Internal.Logger;
17+
#endif
18+
1519
namespace UnityEventTimeline.Internal
1620
{
1721
/// <summary>
@@ -70,7 +74,7 @@ public class EventTimelineBase : MonoBehaviour
7074
public void SetTimeScale(float scale)
7175
{
7276
#if __EVENTTIMELINE_DEBUG_VERBOSE
73-
Debug.Log($"[EventTimelineBase] Setting time scale to {scale}");
77+
AsyncLogger.LogFormat("[EventTimelineBase] Setting time scale to {0}", scale);
7478
#endif
7579

7680
timeScale = scale;
@@ -83,7 +87,7 @@ public void SetTimeScale(float scale)
8387
public void SetPaused(bool paused)
8488
{
8589
#if __EVENTTIMELINE_DEBUG_VERBOSE
86-
Debug.Log($"[EventTimelineBase] Setting paused to {paused}");
90+
AsyncLogger.LogFormat("[EventTimelineBase] Setting paused to {0}", paused);
8791
#endif
8892

8993
isPaused = paused;
@@ -103,15 +107,15 @@ public void RunOnMainThread(Action action)
103107
if (IsMainThread)
104108
{
105109
#if __EVENTTIMELINE_DEBUG_VERBOSE
106-
Debug.Log("[EventTimelineBase] Already on main thread, executing action immediately.");
110+
AsyncLogger.Log("[EventTimelineBase] Already on main thread, executing action immediately.");
107111
#endif
108112

109113
action();
110114
}
111115
else
112116
{
113117
#if __EVENTTIMELINE_DEBUG_VERBOSE
114-
Debug.Log("[EventTimelineBase] Posting action to main thread.");
118+
AsyncLogger.Log("[EventTimelineBase] Posting action to main thread.");
115119
#endif
116120

117121
_mainThreadContext?.Post(_ => action(), null);

0 commit comments

Comments
 (0)