Lifecycle System Refactor & Logging Centralization (#56)

## ManagedBehaviour System Refactor

- **Sealed `Awake()`** to prevent override mistakes that break singleton registration
- **Added `OnManagedAwake()`** for early initialization (fires during registration)
- **Renamed lifecycle hook:** `OnManagedAwake()` → `OnManagedStart()` (fires after boot, mirrors Unity's Awake→Start)
- **40 files migrated** to new pattern (2 core, 38 components)
- Eliminated all fragile `private new void Awake()` patterns
- Zero breaking changes - backward compatible

## Centralized Logging System

- **Automatic tagging** via `CallerMemberName` and `CallerFilePath` - logs auto-tagged as `[ClassName][MethodName] message`
- **Unified API:** Single `Logging.Debug/Info/Warning/Error()` replaces custom `LogDebugMessage()` implementations
- **~90 logging call sites** migrated across 10 files
- **10 redundant helper methods** removed
- All logs broadcast via `Logging.OnLogEntryAdded` event for real-time monitoring

## Custom Log Console (Editor Window)

- **Persistent filter popups** for multi-selection (classes, methods, log levels) - windows stay open during selection
- **Search** across class names, methods, and message content
- **Time range filter** with MinMaxSlider
- **Export** filtered logs to timestamped `.txt` files
- **Right-click context menu** for quick filtering and copy actions
- **Visual improvements:** White text, alternating row backgrounds, color-coded log levels
- **Multiple instances** supported for simultaneous system monitoring
- Open via `AppleHills > Custom Log Console`

Co-authored-by: Michal Pikulski <michal@foolhardyhorizons.com>
Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com>
Reviewed-on: #56
This commit is contained in:
2025-11-11 08:48:29 +00:00
parent c4d356886f
commit 0aa2270e1a
68 changed files with 1541 additions and 1916 deletions

120
docs/custom_log_console.md Normal file
View File

@@ -0,0 +1,120 @@
# Custom Log Console
## Overview
A centralized logging system with an advanced filtering console that automatically tags log entries with class and method names. Provides powerful filtering capabilities beyond Unity's default console, including multi-select filters, text search, time-range filtering, and log export.
## Using the Logging System in Code
All logging automatically captures the calling class and method name using `CallerMemberName` and `CallerFilePath` attributes. Simply call the static logging methods:
```csharp
using Core;
public class MyClass : ManagedBehaviour
{
internal override void OnManagedStart()
{
Logging.Debug("Initialization complete");
Logging.Info("Player spawned at position");
Logging.Warning("Missing configuration, using defaults");
Logging.Error("Failed to load required asset");
}
}
```
**Output format:**
```
[ClassName][MethodName] Your message
```
**Available methods:**
- `Logging.Debug(string message)` - Detailed diagnostic information
- `Logging.Info(string message)` - General informational messages
- `Logging.Warning(string message)` - Non-critical issues
- `Logging.Error(string message)` - Critical errors
**Note:** All logs are broadcast via the `Logging.OnLogEntryAdded` event and stored in a central buffer accessible via `Logging.GetRecentLogs()`.
---
## Opening the Console Window
**Menu:** `AppleHills > Custom Log Console`
You can open multiple independent console instances with different filter configurations to monitor separate systems simultaneously
---
## Console Interface
![Custom Log Console Interface](media/custom_console.png)
### Toolbar Controls
#### 🔵 Basic Controls (Blue outline)
- **Clear** - Clears all log entries and resets tag lists
- **Auto-scroll** - Automatically scrolls to newest entries when enabled
#### Filter Buttons (Persistent Popups)
All filter buttons open persistent popup windows that remain open during multi-selection. Changes apply when you click "Apply" or dismiss with "Close".
- **🔴 Classes Filter (Red outline)**
- Multi-select which classes to display
- Includes search box for quick filtering
- All/None quick actions
- **🟢 Methods Filter (Green outline)**
- Multi-select which methods to display
- Includes search box for quick filtering
- All/None quick actions
- **🟡 Levels Filter (Yellow outline)**
- Toggle Debug, Info, Warning, Error levels
- All/None quick actions
- **⏱ Time Filter**
- Opens utility window with MinMaxSlider
- Filter logs by timestamp range
- Enable/disable toggle with reset option
#### Search & Export
- **Search** - Full-text search across class names, method names, and message content
- **Export** - Save filtered logs to .txt file with timestamp
- **Count** - Shows `filtered/total` log count
---
## Visual Indicators
**Color Coding:**
- White: Debug/Info (normal operation)
- Yellow: Warning (non-critical issues)
- Red: Error (critical failures)
**Alternating Rows:** Light/dark grey backgrounds improve readability for dense log output.
---
## Technical Details
**Event Broadcasting:**
```csharp
Logging.OnLogEntryAdded += (LogEntry entry) => { /* handle */ };
```
**Manual Log Retrieval:**
```csharp
List<LogEntry> recentLogs = Logging.GetRecentLogs();
```
**LogEntry Structure:**
- `ClassName` - Captured from calling file path
- `MethodName` - Captured from `CallerMemberName`
- `Message` - User-provided message text
- `Level` - Debug/Info/Warning/Error enum
- `Timestamp` - Time.realtimeSinceStartup
- `FullFormattedMessage` - Complete formatted string
---