log.html 3.9 KB

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