-
Notifications
You must be signed in to change notification settings - Fork 2
/
Logger.cs
78 lines (73 loc) · 2.94 KB
/
Logger.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
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using JetBrains.Annotations;
namespace Fishing
{
/// <summary>
/// Suggestion: Constructor takes
/// Action<string, Color> Log
/// This is a function that should be passed to the constructor and
/// set by the constructor. Each method can rely on this function
/// to output its message, abstracting from where the logger is created.
/// </summary>
abstract class Logger : ILogger
{
/// <summary>
/// This is a function, set through the constructor, used for logging
/// with Logger classes. This enables the logger to be abstracted from
/// whatever uses it.
/// </summary>
protected readonly Action<string, Color> Log;
/// <summary>
/// Default constructor sets the Log function. Any implementing classes
/// should do the same, or call this constructor.
/// </summary>
/// <param name="logFunc">The logging function to set</param>
protected Logger(Action<string, Color> logFunc)
{
Log = logFunc;
}
/// <summary>
/// Called to format and output a message termed log level Error.
/// Should use the Log property/method.
/// </summary>
/// <param name="message">the Error class message to format and output</param>
/// <param name="args">Optional arguments for use in string.format</param>
[StringFormatMethodAttribute("message")]
public virtual void Error(string message, params object[] args)
{
#if DEBUG
Log(args.Length > 0 ? string.Format(message, args) : message, Color.Red);
#endif
}
/// <summary>
/// Called to format and output a message termed log level Warning.
/// Should use the Log property/method.
/// </summary>
/// <param name="message">the Warning class message to format and output</param>
/// <param name="args">Optional arguments for use in string.format</param>
[StringFormatMethodAttribute("message")]
public virtual void Warning(string message, params object[] args)
{
#if DEBUG
Log(args.Length > 0 ? string.Format(message, args) : message, Color.Yellow);
#endif
}
/// <summary>
/// Called to format and output a message termed log level Info.
/// Should use the Log property/method.
/// </summary>
/// <param name="message">the Info class message to format and output</param>
/// <param name="args">Optional arguments for use in string.format</param>
[StringFormatMethodAttribute("message")]
public virtual void Info(string message, params object[] args)
{
#if DEBUG
Log(args.Length > 0 ? string.Format(message, args) : message, Color.White);
#endif
}
}
}