[250] | 1 | using AllocsFixes.JSON;
|
---|
| 2 | using AllocsFixes.PersistentData;
|
---|
| 3 | using System;
|
---|
| 4 | using System.Collections.Generic;
|
---|
| 5 | using System.Net;
|
---|
| 6 |
|
---|
| 7 | namespace AllocsFixes.NetConnections.Servers.Web.API
|
---|
| 8 | {
|
---|
| 9 | public class GetLog : WebAPI {
|
---|
| 10 | public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) {
|
---|
| 11 | int firstLine, lastLine;
|
---|
| 12 |
|
---|
| 13 | if (req.QueryString ["firstLine"] == null || !int.TryParse (req.QueryString ["firstLine"], out firstLine)) {
|
---|
| 14 | firstLine = LogBuffer.Instance.OldestLine;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | JSONObject result = new JSONObject ();
|
---|
| 18 |
|
---|
[253] | 19 | List<LogBuffer.LogEntry> logEntries = LogBuffer.Instance.GetRange (ref firstLine, 50, out lastLine);
|
---|
[250] | 20 |
|
---|
| 21 | JSONArray entries = new JSONArray ();
|
---|
| 22 | foreach (LogBuffer.LogEntry logEntry in logEntries) {
|
---|
| 23 | JSONObject entry = new JSONObject ();
|
---|
| 24 | entry.Add ("date", new JSONString (logEntry.date));
|
---|
| 25 | entry.Add ("time", new JSONString (logEntry.time));
|
---|
| 26 | entry.Add ("uptime", new JSONString (logEntry.uptime));
|
---|
| 27 | entry.Add ("msg", new JSONString (logEntry.message));
|
---|
| 28 | entry.Add ("trace", new JSONString (logEntry.trace));
|
---|
| 29 | entry.Add ("type", new JSONString (logEntry.type.ToString ()));
|
---|
| 30 | entries.Add (entry);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | result.Add ("firstLine", new JSONNumber (firstLine));
|
---|
| 34 | result.Add ("lastLine", new JSONNumber (lastLine));
|
---|
| 35 | result.Add ("entries", entries);
|
---|
| 36 |
|
---|
| 37 | WriteJSON (resp, result);
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|