Skip to content

ADONE-Games/CustomDebugLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CustomDebugLogger

Unity Unity .Net LICENSE
DebugLog

Table of Contents


Description

Add custom processing before being displayed in the console using Debug.Log, Debug.LogWarning, Debug.LogError, etc.

Installation

Install from Unity Package Manager.

  • Window -> Package Manager
  • "+" -> Add package from git URL...
    https://github.com/ADONE-Games/CustomDebugLogger.git?path=/Assets/LogSystem

Function structure

classDiagram
  direction TB

    class ILogHandler {
        <<interface>>
        + LogFormat(LogType, UnityEngine.Object, string, params object[]): ~void~
        + LogException(Exception, Object): ~void~
    }
    class ILogger {
        <<interface>>
        + logHandler : ~ILogHandler~
    }
    class Debug {
        + Log(string): ~void~
        + Log(string, UnityEngine.Object): ~void~
        + LogWarning(string): ~void~
        + LogWarning(string, UnityEngine.Object): ~void~
        + LogError(string): ~void~
        + LogError(string, UnityEngine.Object): ~void~
    }
    class Logger{
        + logHandler[ LoggerEventManager ] : ILogHandler
    }

    class IDisposable {
        <<interface>>
        + Dispose(): ~void~
    }

    class ILoggerEvent {
        <<interface>>
    }
    class LoggerEventManager {
        - OriginalDebugLogHandler[ DebugLogHandler ] : ~ILogHandler~
        + LogForamt(LogType, UnityEngine.Object, string, params object[]): ~void~
        + LogException(Exception, UnityEngine.Object): ~void~
    }

    class LoggerSetup {
        + Initialize(params LoggerEventFactory[]): ~AbstractLoggerEvent~
    }
    class AbstractLoggerEvent {
        <<abstract>>
        # OriginalDebugLogHandler : ~ILogHandler~
        + LogForamt(LogType, UnityEngine.Object, string, params object[])*: abstract ~void~
        + LogException(Exception, UnityEngine.Object)*: abstract ~void~
        + Dispose(): virtual ~void~
    }

    class ConsoleLoggerEvent {
        + LogForamt(LogType, UnityEngine.Object, string, params object[]): ~void~
        + LogException(Exception, UnityEngine.Object): ~void~
    }
    class FileLoggerEvent {
        + LogForamt(LogType, UnityEngine.Object, string, params object[]): ~void~
        + LogException(Exception, UnityEngine.Object): ~void~
    }

    class AbstractLoggerController{
        <<abstract>>
        # Prefix : abstract ~string~ 
        + Log(string)$ : ~void~
        + Log(string, UnityEngine.Color32)$ : ~void~
        + LogWarning(string)$ : ~void~
        + LogWarning(string, UnityEngine.Color32)$ : ~void~
        + LogError(string)$ : ~void~
    }
    class ConsoleLoggerController{
        # Prefix : ~string~
    }

    class DebugLogHandler [ "DebugLogHandler : < ILogHandler>" ]
    class console

    class FileOutput

    ILogHandler <|-- Logger
    ILogHandler <|-- ILogger
    ILogger <|-- Logger
    Debug --> Logger

    ILogHandler <|-- ILoggerEvent
    IDisposable <|-- ILoggerEvent
    ILoggerEvent <|-- AbstractLoggerEvent
    ILoggerEvent <|-- LoggerEventManager
    Logger --> LoggerEventManager

    LoggerEventManager *-- LoggerSetup
    LoggerSetup <-- AbstractLoggerEvent
    AbstractLoggerEvent <|.. ConsoleLoggerEvent
    AbstractLoggerEvent <|.. FileLoggerEvent
    
    FileLoggerEvent --> FileOutput
    ConsoleLoggerEvent --> DebugLogHandler
    DebugLogHandler --> console
    AbstractLoggerEvent"use" -- DebugLogHandler
    

    Debug <-- ConsoleLoggerController : Send Debug.Log / Debug.LogWarning / Debug.LogError messages
    AbstractLoggerController <|-- ConsoleLoggerController
Loading
The original structure of the Debug.Log series
classDiagram
  direction TB

    class ILogHandler {
        <<interface>>
        + LogFormat(LogType, UnityEngine.Object, string, params object[]): ~void~
        + LogException(Exception, UnityEngine.Object): ~void~
    }
    class ILogger {
        <<interface>>
        + logHandler : ~ILogHandler~
    }
    class Debug {
        + Log(string): ~void~
        + Log(string, UnityEngine.Object): ~void~
        + LogWarning(string): ~void~
        + LogWarning(string, UnityEngine.Object): ~void~
        + LogError(string): ~void~
        + LogError(string, UnityEngine.Object): ~void~
    }
    class Logger{
        + logHandler[DebugLogHandler] : ~ILogHandler~
    }
   
    class DebugLogHandler [ "DebugLogHandler : ~ILogHandler~" ]
    class console

    ILogHandler <|-- Logger
    ILogHandler <|-- ILogger
    ILogger <|-- Logger
    Debug --> Logger

    Logger --> DebugLogHandler
    DebugLogHandler --> console
Loading

Usage

Create your own class inheriting from ADONEGames.CustomDebugLogger.AbstractLoggerEvent.
Specify it using ADONEGames.CustomDebugLogger.LoggerSetup.Initialize( params LoggerEventFactory[] ).


Initialize

Example 1

    public class LoggerTest : MonoBehaviour
    {
        private void Start()
        {
            LoggerSetup.Initialize( handler => new ConsoleLoggerEvent( handler ), handler => new FileLoggerEvent( handler ) );
        }
    }

Example 2

    public class LoggerTest
    {
        // Auto-start before the splash scene
        [RuntimeInitializeOnLoadMethod( RuntimeInitializeLoadType.BeforeSplashScreen )]
        private static void Initialize()
        {
            LoggerSetup.Initialize( handler => new ConsoleLoggerEvent( handler ), handler => new FileLoggerEvent( handler ) );
        }
    }

Run

    public class ButtonTrigger : MonoBehaviour
    {
        public void OnClick_NormalDebugLog()
        {
            Debug.Log( "Button Clicked!" );
        }
        public void OnClick_CustomDebugLog()
        {
            MyClassLoggerController.Log( "ボタン クリック!", Color.magenta );
        }
    }
CustomDebugLogger_DemoPlay.mov

Provided Event Functionality

ADONEGames.CustomDebugLogger
AbstractLoggerEvent Abstract class for additional processing
ADONEGames.CustomDebugLogger
ConsoleLoggerEvent Console display Inherit from AbstractLoggerEvent
FileLoggerEvent File output Inherit from AbstractLoggerEvent

Registering Events

ADONEGames.CustomDebugLogger
LoggerSetup - Initialization Class
- Initialize(params LoggerEventFactory[]) Registration of additional processing
LoggerSetup.Initialize( handler => new ConsoleLoggerEvent( handler ), handler => new FileLoggerEvent( handler ) );

Provided Controller Functionality

ADONEGames.CustomDebugLogger
AbstractLoggerController Abstract class for the controller
ADONEGames.CustomDebugLogger
ConsoleLoggerController Console display Inherit from AbstractLoggerController
ConsoleLoggerController.Log( "Hello World!" );
ConsoleLoggerController.Log( "Hello World!", new Color32( 255, 255, 255, 255 ) );
ConsoleLoggerController.LogWarning( "Hello World!" );
ConsoleLoggerController.LogWarning( "Hello World!", new Color32( 255, 255, 255, 255 ) );
ConsoleLoggerController.LogError( "Hello World!" );

License

This software is released under the MIT License.
You are free to use it within the bounds of the license.
When using it, please include the following copyright and license notices.

LICENSE