OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
LogLinesAJAX.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Reflection;
32 using System.Text;
33 using System.Text.RegularExpressions;
34 using Mono.Data.SqliteClient;
35 using OpenMetaverse;
36 using OpenMetaverse.StructuredData;
37 using OpenSim.Region.Framework.Scenes;
38 using OpenSim.Framework.Monitoring;
39 
40 namespace OpenSim.Region.UserStatistics
41 {
43  {
44  private Regex normalizeEndLines = new Regex(@"\r\n", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.Multiline);
45 
46  private Regex webFormat = new Regex(@"[^\s]*\s([^,]*),[^\s]*\s([A-Z]*)[^\s-][^\[]*\[([^\]]*)\]([^\n]*)",
47  RegexOptions.Singleline | RegexOptions.Compiled);
48  private Regex TitleColor = new Regex(@"[^\s]*\s(?:[^,]*),[^\s]*\s(?:[A-Z]*)[^\s-][^\[]*\[([^\]]*)\](?:[^\n]*)",
49  RegexOptions.Singleline | RegexOptions.Compiled);
50 
51 
52  #region IStatsController Members
53 
54  public string ReportName
55  {
56  get { return ""; }
57  }
58 
59  public Hashtable ProcessModel(Hashtable pParams)
60  {
61  Hashtable nh = new Hashtable();
62  nh.Add("loglines", pParams["LogLines"]);
63  return nh;
64  }
65 
66  public string RenderView(Hashtable pModelResult)
67  {
68  StringBuilder output = new StringBuilder();
69 
70  HTMLUtil.HR(ref output, "");
71  output.Append("<H3>ActiveLog</H3>\n");
72 
73  string tmp = normalizeEndLines.Replace(pModelResult["loglines"].ToString(), "\n");
74 
75  string[] result = Regex.Split(tmp, "\n");
76 
77  string formatopen = "";
78  string formatclose = "";
79 
80  for (int i = 0; i < result.Length; i++)
81  {
82  if (result[i].Length >= 30)
83  {
84  string logtype = result[i].Substring(24, 6);
85  switch (logtype)
86  {
87  case "WARN ":
88  formatopen = "<font color=\"#7D7C00\">";
89  formatclose = "</font>";
90  break;
91 
92  case "ERROR ":
93  formatopen = "<font color=\"#FF0000\">";
94  formatclose = "</font>";
95  break;
96 
97  default:
98  formatopen = "";
99  formatclose = "";
100  break;
101 
102  }
103  }
104  StringBuilder replaceStr = new StringBuilder();
105  //string titlecolorresults =
106 
107  string formatresult = Regex.Replace(TitleColor.Replace(result[i], "$1"), "[^ABCDEFabcdef0-9]", "");
108  if (formatresult.Length > 6)
109  {
110  formatresult = formatresult.Substring(0, 6);
111 
112  }
113  for (int j = formatresult.Length; j <= 5; j++)
114  formatresult += "0";
115  replaceStr.Append("$1 - [<font color=\"#");
116  replaceStr.Append(formatresult);
117  replaceStr.Append("\">$3</font>] $4<br />");
118  string repstr = replaceStr.ToString();
119 
120  output.Append(formatopen);
121  output.Append(webFormat.Replace(result[i], repstr));
122  output.Append(formatclose);
123  }
124 
125 
126  return output.ToString();
127  }
128 
142  public string RenderJson(Hashtable pModelResult)
143  {
144  OSDMap logInfo = new OpenMetaverse.StructuredData.OSDMap();
145 
146  OSDArray logLines = new OpenMetaverse.StructuredData.OSDArray();
147  string tmp = normalizeEndLines.Replace(pModelResult["loglines"].ToString(), "\n");
148  string[] result = Regex.Split(tmp, "\n");
149  for (int i = 0; i < result.Length; i++)
150  {
151  logLines.Add(new OSDString(result[i]));
152  }
153  logInfo.Add("logLines", logLines);
154  return logInfo.ToString();
155  }
156 
157  #endregion
158  }
159 }
OpenMetaverse.StructuredData.OSDArray OSDArray
OpenMetaverse.StructuredData.OSDMap OSDMap
string RenderView(Hashtable pModelResult)
Definition: LogLinesAJAX.cs:66
string RenderJson(Hashtable pModelResult)
Return the last log lines. Output in the format:
Hashtable ProcessModel(Hashtable pParams)
Definition: LogLinesAJAX.cs:59