-
Notifications
You must be signed in to change notification settings - Fork 1
/
DebugLogger.cs
73 lines (61 loc) · 2.14 KB
/
DebugLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using DiscordRPC.Logging;
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace RecklessBoon.MacroDeck.Discord
{
public class DebugLogger : ILogger
{
private AppLogger _logger;
public DebugLogger(AppLogger logger)
{
_logger = logger;
}
private LogLevel _level = LogLevel.Trace;
public LogLevel Level {
get { return _level; }
set { _level = value; }
}
public void Error(string message, params object[] args)
{
if (args.Length > 0) message = String.Format(message, args);
message = RedactSensitive(message);
_logger.Error(message);
}
public void Info(string message, params object[] args)
{
if (args.Length > 0) message = String.Format(message, args);
message = RedactSensitive(message);
_logger.Info(message);
}
public void Trace(string message, params object[] args)
{
if (args.Length > 0) message = String.Format(message, args);
message = RedactSensitive(message);
_logger.Trace(message);
}
public void Warning(string message, params object[] args)
{
if (args.Length > 0) message = String.Format(message, args);
message = RedactSensitive(message);
_logger.Warning(message);
}
private string RedactSensitive(string message)
{
// If we're debugging, I actually want to see this information
if (Debugger.IsAttached) return message;
var redaction = message;
try
{
redaction = redaction.Replace(PluginInstance.Plugin.configuration.ClientSecret, "********");
}
catch (Exception)
{
// No need to break the app if the config isn't set yet somehow
// Just being extra clinchy here
}
redaction = Regex.Replace(redaction, @"(.*{""access_token"":\s*"")(.*)(""\s*}.*)", "$1********$3");
return redaction;
}
}
}