This package provides a custom debug logger for Unity projects. It allows you to log messages with different log levels and colors, and provides customization options through a scriptable object.
- Log messages with different log levels (Info, Warning, Error)
- Customize log colors for each log level
- Scriptable object for easy configuration
- Conditional compilation for editor and debug builds
- Dependency injection support using Zenject
- Download the
DebugLogger.unitypackagefile from the releases page. - In your Unity project, go to "Assets" -> "Import Package" -> "Custom Package".
- Select the downloaded package file and click "Import".
- (Optional) If you want to use dependency injection with Zenject:
- Make sure you have Zenject installed in your project. You can install it via the Unity Package Manager or by downloading it from the Zenject repository.
- Add the
LoggerInstallerscript to your project's installers.
-
Create an instance of the
DebugLoggerclass in your script:using Core.Application.Logging; public class MyScript : MonoBehaviour { private IDebugLogger logger; private void Awake() { logger = new DebugLogger(); } }
-
Use the logging methods to log messages:
logger.Log("This is an info message"); logger.LogWarning("This is a warning message"); logger.LogError("This is an error message");
-
Customize the log settings by modifying the
LogSettingsscriptable object in the "Resources" folder.
-
Add the
LoggerInstallerscript to your project's installers:using Core.Application.Logging; using Zenject; public class LoggerInstaller : MonoInstaller { public override void InstallBindings() { Container.Bind<IDebugLogger>().To<DebugLogger>().AsSingle().NonLazy(); } }
-
Inject the
IDebugLoggerinterface into your scripts:using Core.Application.Logging; using Zenject; public class ExampleWithDI { [Inject] private IDebugLogger _debugLogger; public void Test() { _debugLogger.Log("Test"); _debugLogger.LogWarning("Test"); _debugLogger.LogError("Test"); } }