1 | using System;
|
---|
2 | using System.Net;
|
---|
3 | using System.Text;
|
---|
4 | using System.Text.RegularExpressions;
|
---|
5 | using AllocsFixes.JSON;
|
---|
6 | using UnityEngine;
|
---|
7 |
|
---|
8 | namespace AllocsFixes.NetConnections.Servers.Web.SSE {
|
---|
9 | public class EventLog : EventBase {
|
---|
10 | private static readonly Regex logMessageMatcher =
|
---|
11 | new Regex (@"^([0-9]{4}-[0-9]{2}-[0-9]{2})T([0-9]{2}:[0-9]{2}:[0-9]{2}) ([0-9]+[,.][0-9]+) [A-Z]+ (.*)$");
|
---|
12 |
|
---|
13 | public EventLog (SseHandler _parent) : base (_parent, _name: "log") {
|
---|
14 | Logger.Main.LogCallbacks += LogCallback;
|
---|
15 | }
|
---|
16 |
|
---|
17 |
|
---|
18 | private void LogCallback (string _msg, string _trace, LogType _type) {
|
---|
19 | Match match = logMessageMatcher.Match (_msg);
|
---|
20 |
|
---|
21 | string date;
|
---|
22 | string time;
|
---|
23 | string uptime;
|
---|
24 | string message;
|
---|
25 | if (match.Success) {
|
---|
26 | date = match.Groups [1].Value;
|
---|
27 | time = match.Groups [2].Value;
|
---|
28 | uptime = match.Groups [3].Value;
|
---|
29 | message = match.Groups [4].Value;
|
---|
30 | } else {
|
---|
31 | DateTime dt = DateTime.Now;
|
---|
32 | date = $"{dt.Year:0000}-{dt.Month:00}-{dt.Day:00}";
|
---|
33 | time = $"{dt.Hour:00}:{dt.Minute:00}:{dt.Second:00}";
|
---|
34 | uptime = "";
|
---|
35 | message = _msg;
|
---|
36 | }
|
---|
37 |
|
---|
38 | JSONObject data = new JSONObject ();
|
---|
39 | data.Add ("msg", new JSONString (message));
|
---|
40 | data.Add ("type", new JSONString (_type.ToStringCached ()));
|
---|
41 | data.Add ("trace", new JSONString (_trace));
|
---|
42 | data.Add ("date", new JSONString (date));
|
---|
43 | data.Add ("time", new JSONString (time));
|
---|
44 | data.Add ("uptime", new JSONString (uptime));
|
---|
45 |
|
---|
46 | SendData ("logLine", data);
|
---|
47 | }
|
---|
48 |
|
---|
49 | }
|
---|
50 | }
|
---|