-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cs
98 lines (80 loc) · 2.78 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using ElfKingdom;
using System.Collections.Generic;
namespace SkillZ
{
static class Logger
{
private static LogLevel debug = new LogLevel(true, 220, 750);
private static LogLevel info = new LogLevel(true, 0, 750);
private static LogLevel warn = new LogLevel(true, 0, 750);
private static LogLevel error = new LogLevel(true, 0, 750);
public static List<string> lines = new List<string>();
public static void Debug(string format, params object[] stringsToInsert)
{
if (stringsToInsert == null) return;
debug.Println(format, stringsToInsert);
}
public static void Info(string format, params object[] stringsToInsert)
{
if (stringsToInsert == null) return;
info.Println(format, stringsToInsert);
}
public static void Warning(string format, params object[] stringsToInsert)
{
if (stringsToInsert == null) return;
string line = warn.Println(format, stringsToInsert);
if (line != null) lines.Add(line);
}
public static void Error(string format, params object[] stringsToInsert)
{
if (stringsToInsert == null) return;
string line = error.Println(format, stringsToInsert);
if (line != null) lines.Add(line);
}
public static void EnableDebug(bool enable)
{
debug.isActive = enable;
}
/// <summary>
/// This should be called in the last turn as the last thing that the bot is doing
/// </summary>
public static void PrintAllTheWarningAndErrors()
{
foreach(string line in lines)
{
System.Console.WriteLine(line);
}
lines.Clear();
}
private class LogLevel
{
internal bool isActive;
private int startTurn;
private int endTurn;
public LogLevel(bool isActive, int startTurn, int endTurn)
{
this.isActive = isActive;
this.startTurn = startTurn;
this.endTurn = endTurn;
}
public string Println(string format, params object[] strings)
{
if (IsEnabled())
{
string line = string.Format(format, strings);
System.Console.WriteLine(line);
return line;
}
else
{
return null;
}
}
private bool IsEnabled()
{
int turnCount = Constants.Game.Turn;
return isActive && turnCount >= startTurn && turnCount < endTurn;
}
}
}
}