Skip to content

Instantly share code, notes, and snippets.

@Lachee
Created July 23, 2018 06:15
Show Gist options
  • Save Lachee/8e98934b4fd17094aea29d224e05418a to your computer and use it in GitHub Desktop.
Save Lachee/8e98934b4fd17094aea29d224e05418a to your computer and use it in GitHub Desktop.
A logger for Discord RPC C# for use within the Unity3D engine.
class DebugLogger : DiscordRPC.Logging.ILogger
{
public LogLevel Level { get; set; }
public void Info(string message, params object[] args)
{
if (Level != LogLevel.Info) return;
Debug.Log("[DRPC] " + string.Format(message, args));
}
public void Warning(string message, params object[] args)
{
if (Level != LogLevel.Info && Level != LogLevel.Warning) return;
Debug.LogWarning("[DRPC] " + string.Format(message, args));
}
public void Error(string message, params object[] args)
{
if (Level != LogLevel.Info && Level != LogLevel.Warning && Level != LogLevel.Error) return;
Debug.LogError("[DRPC] " + string.Format(message, args));
}
}
@06Games
Copy link

06Games commented Jul 23, 2018

I think you forgot those two lines :

using DiscordRPC.Logging;
using UnityEngine;

And the class need to be public to be used
So we have this :

using DiscordRPC.Logging;
using UnityEngine;

public class DebugLogger : DiscordRPC.Logging.ILogger
{
    public LogLevel Level { get; set; }

    public void Info(string message, params object[] args)
    {
        if (Level != LogLevel.Info) return;
        Debug.Log("[DRPC] " + string.Format(message, args));
    }

    public void Warning(string message, params object[] args)
    {
        if (Level != LogLevel.Info && Level != LogLevel.Warning) return;
        Debug.LogWarning("[DRPC] " + string.Format(message, args));
    }

    public void Error(string message, params object[] args)
    {
        if (Level != LogLevel.Info && Level != LogLevel.Warning && Level != LogLevel.Error) return;
        Debug.LogError("[DRPC] " + string.Format(message, args));
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment