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