source: binary-improvements/MapRendering/Web/API/GetLog.cs@ 282

Last change on this file since 282 was 253, checked in by alloc, 9 years ago

Fixes 6_8_10

File size: 1.4 KB
RevLine 
[250]1using AllocsFixes.JSON;
2using AllocsFixes.PersistentData;
3using System;
4using System.Collections.Generic;
5using System.Net;
6
7namespace 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
Note: See TracBrowser for help on using the repository browser.