-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConsole.cs
98 lines (84 loc) · 2.63 KB
/
Console.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 UnityEngine;
using System.Collections;
using System;
namespace UConsole
{
/// <summary>
/// Handles logging events.
/// </summary>
public static class Console
{
#region Properties
public static string Logs { get { return log; } private set { log = value; } }
#endregion
public static event Action<string> onLogged;
public static void HandleLog(string message, string stackTrace, LogType type)
{
switch (type)
{
case LogType.Error:
Console.Log("<color=red><b>Error: </b></color>" + message);
break;
case LogType.Exception:
Console.Log("<color=orange><b>Exception: </b></color>" + message);
break;
case LogType.Warning:
Console.Log("<color=yellow><b>Warning: </b></color>" + message);
break;
case LogType.Assert:
Console.Log("<color=0000FF><b>Assert: </b></color>" + message);
break;
case LogType.Log:
Console.Log("<color=gray>" + message + "</color>");
break;
}
}
private static string log = "";
/// <summary>
/// Displays a message to console in red.
/// </summary>
public static void LogError(string message)
{
Log("<color=red><b>Error: </b></color>" + message);
}
public static void LogOk(string message)
{
Log("[ <color=green>OK</color> ] " + message);
}
public static void LogFailed(string message)
{
Log("[ <color=red>FAILED</color> ] " + message);
}
/// <summary>
/// Displays a message to console.
/// </summary>
public static void Log(string message)
{
log += message + "\n";
ClipLog();
onLogged(log);
}
public static void Clear()
{
log = string.Empty;
onLogged(log);
}
private static void ClipLog()
{
if (log.Length < 12000)
return;
string[] lines = log.Split('\n');
string[] newLines = new string[lines.Length - 2];
for (int i = 0; i < newLines.Length; ++i)
{
newLines[i] = lines[i + 1];
}
log = "";
foreach (string line in newLines)
log += line + '\n';
if (log.Length > 12000)
ClipLog();
}
}
}