log.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <!DOCTYPE html>
  2. <html lang="en" xml:lang="en">
  3. <head>
  4. <meta charset="UTF-8"/>
  5. <title>Log Viewer</title>
  6. <style>
  7. html,
  8. body {
  9. height: 100%;
  10. margin: 1px;
  11. }
  12. .box {
  13. display: flex;
  14. flex-flow: column;
  15. height: 99.75%;
  16. }
  17. .box .row.header {
  18. flex: 0 1 auto;
  19. }
  20. .box .row.content {
  21. flex: 1 1 auto;
  22. }
  23. .box .row.footer {
  24. flex: 0 1 auto;
  25. }
  26. #log {
  27. font-family: 'Courier New', Courier, monospace;
  28. font-size: small;
  29. }
  30. .button {
  31. padding: 5px 10px;
  32. width: 190px;
  33. font-size: 16px;
  34. }
  35. </style>
  36. <script type="text/javascript" src="common.js?v=$COMMIT_HASH"></script>
  37. </head>
  38. <body>
  39. <div class="box">
  40. <div class="row header">
  41. <button class="button" onClick="reload();">Reload</button>
  42. <button class="button" onClick="window.open(getDomainname() + '/logfileact');">Show Full Log</button>
  43. <button class="button" onClick="window.location.href = getDomainname() + '/fileserver/log/message/'">Show Older Log Files</button>
  44. </div>
  45. <div class="row content" id="log"><br><br><br><b>Loading logfile, please wait...</b></div>
  46. <div class="row footer">
  47. <button class="button" onClick="reload();">Reload</button>
  48. <button class="button" onClick="window.open(getDomainname() + '/logfileact');">Show Full Log</button>
  49. <button class="button" onClick="window.location.href = getDomainname() + '/fileserver/log/message/'">Show Older Log Files</button>
  50. </div>
  51. </div>
  52. </body>
  53. <script>
  54. function reload() {
  55. // document.getElementById('log').innerHTML += "<br><b>Reloading...<b><br><br>";
  56. document.getElementById('log').innerHTML += "<b>Reloading...</b>";
  57. window.scrollBy(0,document.body.scrollHeight);
  58. funcRequest(getDomainname() + '/log');
  59. }
  60. function processLogLine(line, index, arr) {
  61. /* Make sure the whitespaces in the uptime field get persevered */
  62. uptimePart = line.slice(0, line.indexOf("]")).replace(/ /g, "&nbsp;");
  63. line = uptimePart + line.slice(line.indexOf("]"))
  64. if (line.includes("&lt;WRN&gt;")) {
  65. arr[index] = "<span style=\"color:#e83c00\">" + line + "</span>";
  66. }
  67. else if (line.includes("&lt;ERR&gt;")) {
  68. arr[index] = "<span style=\"color:red\"><b>" + line + "</b></span>";
  69. }
  70. else if (line.includes("&lt;DBG&gt;")) {
  71. arr[index] = "<span style=\"color:gray\">" + line + "</span>";
  72. }
  73. else {
  74. arr[index] = line;
  75. }
  76. arr[index] += "<br>";
  77. }
  78. async function funcRequest(url){
  79. await fetch(url)
  80. .then((res) => {
  81. if (!res.ok) {
  82. document.getElementById("log").innerHTML = "HTTP error " + res.status;
  83. }
  84. return res.text();
  85. })
  86. .then((log) => {
  87. log = log.replace(/</g, "&lt;");
  88. log = log.replace(/>/g, "&gt;");
  89. logArr = log.split("\n");
  90. logArr.forEach(processLogLine);
  91. document.getElementById('log').innerHTML = "<br>" + logArr.join("\n") + "&nbsp;";
  92. window.scrollBy(0,document.body.scrollHeight);
  93. })
  94. .catch((err) => {
  95. document.getElementById("log").innerHTML = err;
  96. });
  97. }
  98. funcRequest(getDomainname() + '/log');
  99. </script>
  100. </html>