1
0

LogLinesAJAX.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using System.Text;
  32. using System.Text.RegularExpressions;
  33. using Mono.Data.SqliteClient;
  34. using OpenMetaverse;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Framework.Statistics;
  37. namespace OpenSim.Region.UserStatistics
  38. {
  39. public class LogLinesAJAX : IStatsController
  40. {
  41. private Regex normalizeEndLines = new Regex(@"\r\n", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.Multiline);
  42. private Regex webFormat = new Regex(@"[^\s]*\s([^,]*),[^\s]*\s([A-Z]*)[^\s-][^\[]*\[([^\]]*)\]([^\n]*)",
  43. RegexOptions.Singleline | RegexOptions.Compiled);
  44. private Regex TitleColor = new Regex(@"[^\s]*\s(?:[^,]*),[^\s]*\s(?:[A-Z]*)[^\s-][^\[]*\[([^\]]*)\](?:[^\n]*)",
  45. RegexOptions.Singleline | RegexOptions.Compiled);
  46. #region IStatsController Members
  47. public string ReportName
  48. {
  49. get { return ""; }
  50. }
  51. public Hashtable ProcessModel(Hashtable pParams)
  52. {
  53. Hashtable nh = new Hashtable();
  54. nh.Add("loglines", pParams["LogLines"]);
  55. return nh;
  56. }
  57. public string RenderView(Hashtable pModelResult)
  58. {
  59. StringBuilder output = new StringBuilder();
  60. HTMLUtil.HR(ref output, "");
  61. output.Append("<H3>ActiveLog</H3>\n");
  62. string tmp = normalizeEndLines.Replace(pModelResult["loglines"].ToString(), "\n");
  63. string[] result = Regex.Split(tmp, "\n");
  64. string formatopen = "";
  65. string formatclose = "";
  66. for (int i = 0; i < result.Length; i++)
  67. {
  68. if (result[i].Length >= 30)
  69. {
  70. string logtype = result[i].Substring(24, 6);
  71. switch (logtype)
  72. {
  73. case "WARN ":
  74. formatopen = "<font color=\"#7D7C00\">";
  75. formatclose = "</font>";
  76. break;
  77. case "ERROR ":
  78. formatopen = "<font color=\"#FF0000\">";
  79. formatclose = "</font>";
  80. break;
  81. default:
  82. formatopen = "";
  83. formatclose = "";
  84. break;
  85. }
  86. }
  87. StringBuilder replaceStr = new StringBuilder();
  88. //string titlecolorresults =
  89. string formatresult = Regex.Replace(TitleColor.Replace(result[i], "$1"), "[^ABCDEFabcdef0-9]", "");
  90. if (formatresult.Length > 6)
  91. {
  92. formatresult = formatresult.Substring(0, 6);
  93. }
  94. for (int j = formatresult.Length; j <= 5; j++)
  95. formatresult += "0";
  96. replaceStr.Append("$1 - [<font color=\"#");
  97. replaceStr.Append(formatresult);
  98. replaceStr.Append("\">$3</font>] $4<br />");
  99. string repstr = replaceStr.ToString();
  100. output.Append(formatopen);
  101. output.Append(webFormat.Replace(result[i], repstr));
  102. output.Append(formatclose);
  103. }
  104. return output.ToString();
  105. }
  106. #endregion
  107. }
  108. }