Sometimes you just need an on-screen logger which is lightweight, simple, customizable and no more. Screen logging is very useful when you are testing a build of your game, for example when you are building for mobile or consoles, or when you are testing things like screen resolution management which cannot be tested in editor.
Screen Logger is a fully customizable screen logger. Just put it on a scene and you’ll see on-screen output for each call to Debug.Log
/ Debug.LogWarning
/ Debug.LogError
.
Features
- Persistent
- Filter by message type
- Adjust font size
- Adjust color for each message type
- Adjust overlay size, anchoring and background color/opacity
- Toggle stack trace logging for each message type
- Toggle in editor visualization
Requires Unity 4.7 or higher.
Get Started
Screen Logger intercepts every call to Debug.Log
/ Debug.LogWarning
/ Debug.LogError
and displays each log message on a customizable screen overlay. You won’t need to add extra logging logic to your code; you will get on-screen the same output you see in editor including stack traces.
Open a scene and select from main menu: GameObject > Create Other > Screen Logger
. A new ScreenLogger
game object will be added to your scene. From this object you can customize all the logging features using the inspector. If you add the Screen Logger to the game’s first scene and you set to true the Is Persistent
flag, the object will persist with all the log text when loading new game scenes.
Control Screen Logger using code
You can also add the logger to your scene by code. The ScreenLogger class implements a Singleton pattern and you can always access the unique instance of ScreenLogger from AClockworkBerry.ScreenLogger.Instance
.
If you want to add a Screen Logger to your scene using code, just write this:
1 |
AClockworkBerry.ScreenLogger.Instance.ShowLog = true; |
If no logger has been added to the scene yet, the first call to AClockworkBerry.ScreenLogger.Instance
will create a new ScreenLogger and add it to the scene.
Then you can use the showLog
property to toggle on/off visibility of the log overlay.
1 2 3 4 5 |
// Shows the screen logger (creates and adds it to the scene if it doesn't exist) AClockworkBerry.ScreenLogger.Instance.ShowLog = true; // Hides the screen logger AClockworkBerry.ScreenLogger.Instance.ShowLog = false; |
Default Values
When you add a Screen Logger from code, the object default values will be loaded from a prefab placed in ScreenLogger/Resources/ScreenLoggerPrefab.prefab
You can edit these default properties by selecting the prefab and editing its values from the inspector as usual.
Properties
- Is Persistent – if set to true, the Screen Logger object will persist when you load a new scene
- Show in Editor – useful to preview the log overlay in editor
- Height – the height of the log overlay as a percentage of the screen height
- Width – the hwidth of the log overlay as a percentage of the screen width
- Margin – margin of the log overlay in pixels from the screen borders
- Anchor Position – top-left, top-right, bottom-left, bottom-right
- Font Size – log text font size
- Background Opacity – 0 is transparent, 1 is totally opaque
- Background Color – background color for the log overlay
- Log Messages – toggles log messages output
- Log Warnings – toggles warning messages output
- Log Errors – toggles errors/asserts/exceptions output
- Message Color – text color for log messages
- Warning Color – text color for warning messages
- Error Color – text color for error/assert/exception messages
- Stack Trace Messages – toggles stack trace log for messages
- Stack Trace Warnings – toggles stack trace log for warnings
- Stack Trace Errors – toggles stack trace log for errors/asserts/exceptions