Last active
January 7, 2019 05:47
-
-
Save roydejong/9681cc6f27f2d354be1b111178ac22ce to your computer and use it in GitHub Desktop.
Unity: Debug logger class for the DiscordRPC C# Wrapper Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DiscordRPC.Logging; | |
using System; | |
using UnityEngine; | |
public class DiscordDebugLogger : DiscordRPC.Logging.ILogger | |
{ | |
/// <summary> | |
/// The level of logging to apply to this logger. | |
/// </summary> | |
public LogLevel Level { get; set; } | |
/// <summary> | |
/// Should the output be coloured? | |
/// </summary> | |
public bool Coloured { get; set; } | |
/// <summary> | |
/// A alias too <see cref="Coloured"/> | |
/// </summary> | |
public bool Colored { get { return Coloured; } set { Coloured = value; } } | |
/// <summary> | |
/// Informative log messages | |
/// </summary> | |
/// <param name="message"></param> | |
/// <param name="args"></param> | |
public void Info(string message, params object[] args) | |
{ | |
if (Level != LogLevel.Info) return; | |
if (Coloured) Console.ForegroundColor = ConsoleColor.White; | |
Debug.LogFormat("[DRP] (Logger) " + message, args); | |
} | |
/// <summary> | |
/// Warning log messages | |
/// </summary> | |
/// <param name="message"></param> | |
/// <param name="args"></param> | |
public void Warning(string message, params object[] args) | |
{ | |
if (Level != LogLevel.Info && Level != LogLevel.Warning) return; | |
if (Coloured) Console.ForegroundColor = ConsoleColor.Yellow; | |
Debug.LogWarningFormat("[DRP] (Logger) " + message, args); | |
} | |
/// <summary> | |
/// Error log messsages | |
/// </summary> | |
/// <param name="message"></param> | |
/// <param name="args"></param> | |
public void Error(string message, params object[] args) | |
{ | |
if (Level != LogLevel.Info && Level != LogLevel.Warning && Level != LogLevel.Error) return; | |
if (Coloured) Console.ForegroundColor = ConsoleColor.Red; | |
Debug.LogErrorFormat("[DRP] (Logger) " + message, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example use: