logview.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <!DOCTYPE html>
  2. <html ng-app="App">
  3. <head>
  4. <title>System Logs</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  7. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  8. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  9. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  10. <style>
  11. .clickable{
  12. cursor: pointer;
  13. }
  14. .clickable:hover{
  15. opacity: 0.7;
  16. }
  17. .logfile{
  18. padding-left: 1em !important;
  19. position: relative;
  20. padding-right: 1em !important;
  21. }
  22. .loglist{
  23. background-color: rgb(250, 250, 250);
  24. }
  25. .logfile .showing{
  26. position: absolute;
  27. top: 0.18em;
  28. right: 0em;
  29. margin-right: -0.4em;
  30. opacity: 0;
  31. }
  32. .logfile.active .showing{
  33. opacity: 1;
  34. }
  35. #logrender{
  36. width: 100% !important;
  37. height: calc(100% - 1.2em);
  38. min-height: 50vh;
  39. border: 1px solid rgb(231, 231, 231);
  40. font-family: monospace;
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <div class="ui container">
  46. <div class="ui stackable grid">
  47. <div class="four wide column loglist">
  48. <h3 class="ui header" style="padding-top: 1em;">
  49. <div class="content">
  50. Log View
  51. <div class="sub header">Check System Log in Real Time</div>
  52. </div>
  53. </h3>
  54. <div class="ui divider"></div>
  55. <div id="logList" class="ui accordion">
  56. </div>
  57. <div class="ui divider"></div>
  58. <small>Notes: Some log file might be huge. Make sure you have checked the log file size before opening</small>
  59. </div>
  60. <div class="twelve wide column">
  61. <textarea id="logrender" spellcheck="false" readonly="true">
  62. ← Pick a log file from the left menu to start debugging
  63. </textarea>
  64. <a href="#" onclick="openLogInNewTab();">Open In New Tab</a>
  65. <br><br>
  66. </div>
  67. </div>
  68. </div>
  69. <div class="ui divider"></div>
  70. <br>
  71. </body>
  72. <script>
  73. var currentOpenedLogURL = "";
  74. function openLogInNewTab(){
  75. if (currentOpenedLogURL != ""){
  76. window.open(currentOpenedLogURL);
  77. }
  78. }
  79. function openLog(object, catergory, filename){
  80. $(".logfile.active").removeClass('active');
  81. $(object).addClass("active");
  82. currentOpenedLogURL = "../../system/log/read?file=" + filename + "&catergory=" + catergory;
  83. $.get(currentOpenedLogURL, function(data){
  84. if (data.error !== undefined){
  85. alert(data.error);
  86. return;
  87. }
  88. $("#logrender").val(data);
  89. });
  90. }
  91. function initLogList(){
  92. $("#logList").html("");
  93. $.get("../../system/log/list", function(data){
  94. //console.log(data);
  95. for (let [key, value] of Object.entries(data)) {
  96. console.log(key, value);
  97. value.reverse(); //Default value was from oldest to newest
  98. var fileItemList = "";
  99. value.forEach(file => {
  100. fileItemList += `<div class="item clickable logfile" onclick="openLog(this, '${key}','${file.Filename}');">
  101. <i class="file outline icon"></i>
  102. <div class="content">
  103. ${file.Title} (${formatBytes(file.Filesize)})
  104. <div class="showing"><i class="green chevron right icon"></i></div>
  105. </div>
  106. </div>`;
  107. })
  108. $("#logList").append(`<div class="title">
  109. <i class="dropdown icon"></i>
  110. ${key}
  111. </div>
  112. <div class="content">
  113. <div class="ui list">
  114. ${fileItemList}
  115. </div>
  116. </div>`);
  117. }
  118. $(".ui.accordion").accordion();
  119. });
  120. }
  121. initLogList();
  122. function formatBytes(x){
  123. var units = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  124. let l = 0, n = parseInt(x, 10) || 0;
  125. while(n >= 1024 && ++l){
  126. n = n/1024;
  127. }
  128. return(n.toFixed(n < 10 && l > 0 ? 1 : 0) + ' ' + units[l]);
  129. }
  130. </script>
  131. </html>