Changeset 369 for binary-improvements/MapRendering/Web/SSE/EventLog.cs
- Timestamp:
- Nov 9, 2021, 6:28:33 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/SSE/EventLog.cs
r367 r369 1 1 using System; 2 using System.Net;3 using System.Text;4 using System.Text.RegularExpressions;5 2 using AllocsFixes.JSON; 6 3 using UnityEngine; … … 8 5 namespace AllocsFixes.NetConnections.Servers.Web.SSE { 9 6 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 7 public EventLog (SseHandler _parent) : base (_parent, _name: "log") { 14 Log ger.Main.LogCallbacks+= LogCallback;8 Log.LogCallbacksExtended += LogCallback; 15 9 } 16 10 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 } 11 private void LogCallback (string _formattedMsg, string _plainMsg, string _trace, LogType _type, DateTime _timestamp, long _uptime) { 12 string date = $"{_timestamp.Year:0000}-{_timestamp.Month:00}-{_timestamp.Day:00}"; 13 string time = $"{_timestamp.Hour:00}:{_timestamp.Minute:00}:{_timestamp.Second:00}"; 14 string uptime = _uptime.ToString (); 15 string message = _plainMsg; 37 16 38 17 JSONObject data = new JSONObject (); … … 46 25 SendData ("logLine", data); 47 26 } 48 49 27 } 50 28 }
Note:
See TracChangeset
for help on using the changeset viewer.