Skip to content

JohnnyHowe/unity-detailed-logs

Repository files navigation

Overview

Default Unity log

Default Unity Log

Prettier Unity log

Prettier Log

Why This Package?

I don't like dependencies on third party packages - or depdencies at all for that matter.

The only reason you will ever need to reference this package in your code is if you want to make a custom log filter and even those are pretty light weight.

Quick Start

Install (UPM)

  1. In Unity, open the Package Manager
    Window > Package Management > Package Manager

  2. Install Package from git URL
    Package Manager > + (in top left) > Install Package from git URL

  3. Paste https://github.com/JohnnyHowe/unity-detailed-logs.git and press Install

(Recommended) If you want a specific version, use
https://github.com/JohnnyHowe/unity-detailed-logs.git#<version>

Usage

The logger will automatically override the default at runtime. No configuration needed.

Custom Configuration

Assets > Create > Detailed Log Configuration
Ensure this file is in a Resources folder and that there is only one.

Jon todo:
  • Ensure file is automatically put into Assets/Resources
  • Give warning/error when user tries to create a second

This file lets you adjust how and when the detailed logger takes over.

Configuration File Screenshot

Log Filtering

The detailed logger can handle filtering out logs based on.

  • Caller
  • Log content
  • Log type

To create a filter, have a class inherit from JonathonOH.Unity.DetailedLogs.DetailedLogFilter and call RegisterFilter onstartup.

Jon todo:
  • Make registering easier
  • Make filter an interface, not an abstract class

Example:

public class ExampleLogFilter : DetailedLogFilter
{
	/// <summary>
	/// Registers the filter in the logger
	/// </summary>
	[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
	private static void CreateFilterObject()
	{
		RegisterFilter(new ExampleLogFilter());
	}

	/// <summary>
	/// Hide Debug.Log statements from MyNamespace.MyClassThatIWantToHideLogsFor
	/// </summary>
	public override bool ShouldHideLog(Type caller, LogType logType, string format)
	{
		// Don't filter if we don't know caller
		if (caller == null)
		{
			return false;
		}

		// Only filter Debug.Logs
		if (logType != LogType.Log)
		{
			return false;
		}

		// Hide logs for a given class
		return caller.FullName.StartsWith("MyNamespace.MyClassThatIWantToHideLogsFor");
	}
}

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages