skner's Logging Toolkit
  • Welcome to skner's Logging Toolkit for Unity
  • Changelog
  • Examples
  • Getting Started
  • Introduction
  • Loggers
    • Class Logger
    • Game Object Logger
    • Global Logger
  • Models
    • Log Context
    • Log Format
    • Log Path
    • Log Tag Holder
  • Output Modules
    • Output Modules
  • Settings
    • Log Level Settings
    • Log Output Settings
    • Logger Settings
Powered by GitBook
On this page
  • Overview
  • Configuring
  • Using
  1. Loggers

Game Object Logger

Last updated 1 year ago

Overview

The Game Object Logger is a MonoBehaviour that wraps logging functionality. The ideal use cases for this logger are for complex Game Object with several components that benefit from specific logging needs.

For example, the Player object often contains several scripts. These can reference a GameObjectLogger, making use of specific Logger Settings.

Configuring

Being a Unity component, setting this logger up is straight forward. In the selected game object, add a new GameObjectLogger script:

In the Logger Settings field, assign an existing Logger Settings:

Using

Once the GameObjectLogger is configured, it can be called in any script from this GameObject with the following code:

private GameObjectLogger _gameObjectLogger;

void Awake()
{
    _gameObjectLogger = GetComponent<GameObjectLogger>();
}

Note: Although it's dependent on the developer, it's advisable to keep this GetComponent call in the Awake method, so that logging is available in the Start method, if required.

To perform a logging call, reference the GameObjectLogger and call its Log method:

_gameObjectLogger.LogDebug("Logging a debug message.");

Note: Read more into how to create and configure a Logger Settings instance .

here
Adding a Game Object Logge component to a Game Object