A comprehensive, high-performance logging system for Unity applications with runtime display capabilities, cross-platform support, and advanced performance monitoring.
- Unified Logging Interface: Consistent
ILogger
interface across all logging implementations - Multiple Logger Types: Unity Console, On-Screen Display, and Composite loggers
- Real-time Log Display: In-game log panel with TextMeshPro integration
- Thread-Safe Operations: Safe concurrent access from multiple threads
- Performance Optimized: Built-in object pooling and memory management
- Cross-Platform Compatibility: Validated support across all Unity platforms
- Performance Monitoring: Real-time performance statistics and memory usage tracking
- Configurable Display: Customizable colors, timestamps, and log count limits
- Modular Architecture: Easy integration and extensibility
- Comprehensive Testing: Extensive test coverage with validation framework
- TextMeshPro Support: High-quality text rendering for log displays
- Runtime Controls: Show/hide, clear logs, and real-time configuration
- Visual Feedback: Color-coded log levels (Info, Warning, Error)
- Performance Dashboard: Built-in performance monitoring display
- Open Unity Package Manager
- Click "Add package from git URL"
- Enter:
https://github.com/CodeTeaBooker/unity-logging-system.git
- Download the latest
.unitypackage
from Releases - Import into your Unity project via
Assets > Import Package > Custom Package
- Clone or download this repository
- Copy the
Assets/Unity.LoggingSystem
folder to your Unity project's Assets folder
using RuntimeLogging;
// Set up a basic Unity console logger
var unityLogger = new UnityLogger();
LogManager.SetLogger(unityLogger);
// Start logging
LogManager.Log("Hello, Unity Logging System!");
LogManager.LogWarning("This is a warning");
LogManager.LogError("This is an error");
// Add ScreenLogger component to a GameObject
var screenLogger = gameObject.AddComponent<ScreenLogger>();
// Set as the global logger
LogManager.SetLogger(screenLogger);
// Configure display settings
screenLogger.UpdateMaxLogCount(100);
screenLogger.UpdateLogLevelColor(LogLevel.Info, "#00FF00");
// Create multiple loggers
var unityLogger = new UnityLogger();
var screenLogger = GetComponent<ScreenLogger>();
// Combine them
var compositeLogger = new CompositeLogger(unityLogger, screenLogger);
LogManager.SetLogger(compositeLogger);
// Now logs appear in both Unity Console and on-screen
LogManager.Log("This appears in both outputs!");
The foundation of the logging system providing consistent logging methods:
Log(string message)
- Information level loggingLogWarning(string message)
- Warning level loggingLogError(string message)
- Error level logging
Central logger management with thread-safe operations:
SetLogger(ILogger logger)
- Set the global loggerGetLogger()
- Get the current loggerLog/LogWarning/LogError(string message)
- Convenience methods
Logs directly to Unity's console system.
MonoBehaviour-based logger with on-screen display:
- TextMeshPro integration for high-quality text rendering
- Configurable colors and display settings
- Performance monitoring and optimization
- Cross-platform compatibility validation
Combines multiple loggers for simultaneous output to different targets.
Centralized configuration management:
var config = LogConfiguration.CreateDefault();
config.maxLogCount = 200;
config.timestampFormat = "HH:mm:ss";
config.infoColor = "#FFFFFF";
config.warningColor = "#FFFF00";
config.errorColor = "#FF0000";
screenLogger.SetConfiguration(config);
// Update settings during runtime
screenLogger.UpdateMaxLogCount(150);
screenLogger.UpdateTimestampFormat("mm:ss");
screenLogger.UpdateLogLevelColor(LogLevel.Warning, "#FFA500");
// Get performance statistics
var stats = screenLogger.GetPerformanceStats();
Debug.Log($"Current logs: {stats.CurrentLogCount}");
Debug.Log($"Memory usage: {stats.EstimatedMemoryUsage} bytes");
Debug.Log($"Initialized: {stats.IsInitialized}");
// Register for performance monitoring
UnifiedPerformanceMonitor.RegisterStats(performanceStats);
// Listen for updates
UnifiedPerformanceMonitor.OnPerformanceStatsUpdated += (name, stats) => {
Debug.Log($"Component {name} updated: {stats.EstimatedMemoryUsage} bytes");
};
The system includes comprehensive validation tests:
// Run all validation tests
demoController.RunAllValidationTests();
// Individual requirement validation
bool realTimeLogging = demoController.ValidateRequirement1_RealTimeLogging();
bool displayControl = demoController.ValidateRequirement2_LogDisplayControl();
bool performance = demoController.ValidateRequirement5_Performance();
The included demo scene demonstrates all features:
- Logger Type Selection: Switch between Unity, Screen, and Composite loggers
- Real-time Controls: Show/hide display, clear logs, configuration changes
- Performance Testing: High-volume logging and performance validation
- Cross-platform Testing: Platform compatibility verification
- Business Logic Integration: Example of logging in game systems
- Open the
DemoScene
in theUnity.LoggingSystem/DemoScenes
folder - Play the scene
- Use the UI buttons to test different logger configurations
- Monitor the on-screen display and Unity console
public class FileLogger : ILogger
{
private string logFilePath;
public FileLogger(string filePath)
{
logFilePath = filePath;
}
public void Log(string message)
{
File.AppendAllText(logFilePath, $"[INFO] {DateTime.Now}: {message}\n");
}
public void LogWarning(string message)
{
File.AppendAllText(logFilePath, $"[WARNING] {DateTime.Now}: {message}\n");
}
public void LogError(string message)
{
File.AppendAllText(logFilePath, $"[ERROR] {DateTime.Now}: {message}\n");
}
}
// Use custom logger
var fileLogger = new FileLogger("game.log");
var compositeLogger = new CompositeLogger(
new UnityLogger(),
GetComponent<ScreenLogger>(),
fileLogger
);
LogManager.SetLogger(compositeLogger);
// Configure memory settings
screenLogger.UpdateMaxLogCount(50); // Limit log history
logConfiguration.enableLogEntryPooling = true; // Enable object pooling
// Monitor memory usage
var memoryMonitor = new MemoryMonitor();
memoryMonitor.OnMemoryThresholdExceeded += (usage) => {
LogManager.LogWarning($"Memory usage high: {usage} MB");
screenLogger.Clear(); // Clear logs to free memory
};
Tested and validated on:
- ✅ Windows (Standalone)
- ✅ macOS (Standalone)
- ✅ Linux (Standalone)
- ✅ iOS
- ✅ Android
// Validate platform compatibility
var validator = new CrossPlatformLoggerValidator();
var result = screenLogger.ValidateCrossPlatformCompatibility();
if (result.CompatibilityReport.IsUnitySupportedVersion)
{
LogManager.Log("Platform compatibility validated");
}
else
{
LogManager.LogWarning("Platform compatibility issues detected");
}
Assets/Unity.LoggingSystem/
├── Core/ # Core interfaces and data structures
│ ├── ILogger.cs
│ ├── LogEntry.cs
│ ├── LogLevel.cs
│ └── LogConstants.cs
├── Loggers/ # Logger implementations
│ ├── UnityLogger.cs
│ ├── ScreenLogger.cs
│ └── CompositeLogger.cs
├── Management/ # Configuration and management
│ ├── LogManager.cs
│ ├── LogConfiguration.cs
│ └── LogConfigurationManager.cs
├── Data/ # Data management and pooling
│ ├── LogDataManager.cs
│ └── LogEntryPool.cs
├── UI/ # User interface components
│ ├── LogDisplay.cs
│ ├── LogUIController.cs
│ └── TextMeshProOptimizer.cs
├── Performance/ # Performance monitoring
│ ├── UnifiedPerformanceMonitor.cs
│ ├── MemoryMonitor.cs
│ └── LoggingPerformanceProfiler.cs
├── Platform/ # Cross-platform compatibility
│ ├── PlatformCompatibility.cs
│ └── CrossPlatformLoggerValidator.cs
├── Examples/ # Example code
│ ├── DemoSceneController.cs
│ ├── DemoBusinessLogic.cs
│ └── ComprehensiveValidationTests.cs
├── DemoScenes/ # Unity demo scenes
├── Tests/ # Unit and integration tests
└── Editor/ # Unity Editor extensions
Issues and Pull Requests are welcome.
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by CodeTeaBooker