Main.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. MWF.xApplication.LogViewer.Main = new Class({
  2. Extends: MWF.xApplication.Common.Main,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "name": "LogViewer",
  7. "icon": "icon.png",
  8. "width": "800",
  9. "height": "600",
  10. "title": MWF.xApplication.LogViewer.LP.title
  11. },
  12. onQueryLoad: function(){
  13. this.lp = MWF.xApplication.LogViewer.LP;
  14. },
  15. loadApplication: function(callback){
  16. if (!this.options.isRefresh){
  17. this.maxSize(function(){
  18. this.doLog();
  19. }.bind(this));
  20. }else{
  21. this.doLog();
  22. }
  23. if (callback) callback();
  24. },
  25. doLog: function(){
  26. this.status = "prompt";
  27. this.actions = MWF.Actions.get("x_program_center");
  28. this.node = new Element("div", {"styles": this.css.contentNode}).inject(this.content);
  29. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode}).inject(this.node);
  30. this.screenNode = new Element("div", {"styles": this.css.screenNode}).inject(this.node);
  31. this.bottomNode = new Element("div", {"styles": this.css.bottomNode}).inject(this.node);
  32. this.loadToolbar();
  33. this.loadScreen();
  34. this.initLog();
  35. this.loadLog();
  36. },
  37. initLog: function(){
  38. this.screenInforAreaNode.empty();
  39. this.date = this.dateSelect.options[this.dateSelect.selectedIndex];
  40. this.method = "listPromptErrorLog";
  41. this.count = 20;
  42. this.currentId = "(0)";
  43. },
  44. loadToolbar: function(){
  45. this.promptErrorButton = this.createTopButton("PromptError", "prompt.png", "prompt");
  46. this.unexpectedErrorButton = this.createTopButton("UnexpectedError", "unexpected.png", "unexpected");
  47. this.warnErrorButton = this.createTopButton("Warn", "warn.png", "warn");
  48. this.dateSelect = new Element("select", {"styles": this.css.toolbarDateSelect}).inject(this.toolbarNode);
  49. new Element("option", {
  50. "value": "all",
  51. "selected": true,
  52. "text": this.lp.current
  53. }).inject(this.dateSelect);
  54. var d = new Date();
  55. var t = d.format("%Y-%m-%d");
  56. new Element("option", { "value": t, "text": t }).inject(this.dateSelect);
  57. for (var i=0; i<=7; i++){
  58. d = d.decrement("day", 1);
  59. t = d.format("%Y-%m-%d");
  60. new Element("option", { "value": t, "text": t }).inject(this.dateSelect);
  61. }
  62. this.dateSelect.addEvent("change", function(){
  63. this.initLog();
  64. this.loadLog();
  65. }.bind(this));
  66. // this.promptErrorButton.addEvent("click", function(){
  67. // this.showTypeLog("prompt");
  68. // }.bind(this));
  69. // this.unexpectedErrorButton.addEvent("click", function(){
  70. // this.showTypeLog("unexpected");
  71. // }.bind(this));
  72. // this.warnErrorButton.addEvent("click", function(){
  73. // this.showTypeLog("warn");
  74. // }.bind(this));
  75. },
  76. showTypeLog: function(status){
  77. if (this.status!==status){
  78. switch (this.status){
  79. case "prompt":
  80. this.promptErrorButton.setStyles(this.css.toolbarButton);
  81. break;
  82. case "unexpected":
  83. this.unexpectedErrorButton.setStyles(this.css.toolbarButton);
  84. break;
  85. case "warn":
  86. this.warnErrorButton.setStyles(this.css.toolbarButton);
  87. break;
  88. }
  89. switch (status){
  90. case "prompt":
  91. this.promptErrorButton.setStyles(this.css.toolbarButton_down);
  92. this.status="prompt";
  93. break;
  94. case "unexpected":
  95. this.unexpectedErrorButton.setStyles(this.css.toolbarButton_down);
  96. this.status="unexpected";
  97. break;
  98. case "warn":
  99. this.warnErrorButton.setStyles(this.css.toolbarButton_down);
  100. this.status="warn";
  101. break;
  102. default:
  103. this.promptErrorButton.setStyles(this.css.toolbarButton_down);
  104. this.status="prompt";
  105. }
  106. this.initLog();
  107. this.loadLog();
  108. }
  109. },
  110. createTopButton: function(text, img, status){
  111. var node = new Element("div", {"styles": this.css.toolbarButton}).inject(this.toolbarNode);
  112. var iconNode = new Element("div", {"styles": this.css.toolbarIconButton}).inject(node);
  113. var textNode = new Element("div", {"styles": this.css.toolbarTextButton, "text": text}).inject(node);
  114. iconNode.setStyle("background-image", "url("+"/x_component_LogViewer/$Main/default/"+img+")");
  115. if (status==this.status) node.setStyles(this.css.toolbarButton_down);
  116. var _self = this;
  117. node.addEvents({
  118. "mouseover": function(){if (_self.status != status) this.setStyles(_self.css.toolbarButton_over);},
  119. "mousedown": function(){if (_self.status != status) this.setStyles(_self.css.toolbarButton_down);},
  120. "mouseup": function(){if (_self.status != status) this.setStyles(_self.css.toolbarButton_over);},
  121. "mouseout": function(){if (_self.status != status) this.setStyles(_self.css.toolbarButton);},
  122. "click": function(){_self.showTypeLog(status);}.bind(this)
  123. });
  124. return node;
  125. },
  126. loadLog: function(){
  127. this.date = this.dateSelect.options[this.dateSelect.selectedIndex].value;
  128. switch (this.status){
  129. case "prompt":
  130. this.method = (this.date==="all") ? "listPromptErrorLog" : "listPromptErrorLogWithDate";
  131. break;
  132. case "unexpected":
  133. this.method = (this.date==="all") ? "listUnexpectedErrorLog" : "listUnexpectedErrorLogWithDate";
  134. break;
  135. case "warn":
  136. this.method = (this.date==="all") ? "listWarnLog" : "listWarnLogWithDate";
  137. break;
  138. default:
  139. this.method = (this.date==="all") ? "listPromptErrorLog" : "listPromptErrorLogWithDate";
  140. }
  141. if (this.date==="all"){
  142. this.actions[this.method](this.currentId, this.count, function(json){
  143. this.showLog(json.data);
  144. }.bind(this));
  145. }else{
  146. var d = new Date().parse(this.date).format("%Y-%m-%d");
  147. this.actions[this.method](this.currentId, this.count, d, function(json){
  148. this.showLog(json.data);
  149. }.bind(this));
  150. }
  151. },
  152. showLog: function(data){
  153. if (data.length){
  154. var last = data[data.length-1];
  155. this.currentId = last.id;
  156. data.each(function(log){
  157. new MWF.xApplication.LogViewer.Log(log, this);
  158. }.bind(this));
  159. // switch (this.status){
  160. // case "prompt":
  161. // this.showPromptLog(data);
  162. // break;
  163. // case "unexpected":
  164. // this.showUnexpectedLog(data);
  165. // break;
  166. // case "warn":
  167. // this.showWarnLog(data);
  168. // break;
  169. // default:
  170. // this.showPromptLog(data);
  171. // }
  172. }else{
  173. this.logFinish = true;
  174. }
  175. this.checkLoadNext();
  176. },
  177. checkLoadNext: function(){
  178. if (!this.logFinish){
  179. var s = this.screenInforAreaNode.getScroll();
  180. var ssize = this.screenInforAreaNode.getScrollSize();
  181. var size = this.screenInforAreaNode.getSize();
  182. if (ssize.y-s.y-size.y<200){
  183. this.loadLog();
  184. }
  185. }
  186. },
  187. // showPromptLog: function(data){
  188. // data.each(function(log){
  189. // new MWF.xApplication.LogViewer.Log(log, this);
  190. // }.bind(this));
  191. // },
  192. begin: function(){
  193. this.beginButton.setStyle("background-image", "url("+"/x_component_Console/$Main/default/play_gray.png)");
  194. this.stopButton.setStyle("background-image", "url("+"/x_component_Console/$Main/default/stop.png)");
  195. this.status = "begin";
  196. },
  197. stop: function(){
  198. this.beginButton.setStyle("background-image", "url("+"/x_component_Console/$Main/default/play.png)");
  199. this.stopButton.setStyle("background-image", "url("+"/x_component_Console/$Main/default/stop_gray.png)");
  200. this.status = "stop";
  201. },
  202. loadScreen: function(){
  203. this.screenInforAreaNode = new Element("div", {"styles": this.css.screenInforAreaNode}).inject(this.screenNode);
  204. this.screenInforAreaNode.addEvent("scroll", function(){
  205. this.checkLoadNext();
  206. }.bind(this));
  207. //this.screenInforAreaNode = new Element("div", {"styles": this.css.screenInforAreaNode}).inject(this.screenScrollNode);
  208. // MWF.require("MWF.widget.ScrollBar", function(){
  209. // new MWF.widget.ScrollBar(this.screenScrollNode, {
  210. // "style":"xApp_console", "where": "before", "indent": false, "distance": 50, "friction": 6, "axis": {"x": false, "y": true},
  211. // "onScroll": function(y, x){
  212. // // var scrollSize = _self.listScrollAreaNode.getScrollSize();
  213. // // var clientSize = _self.listScrollAreaNode.getSize();
  214. // // var scrollHeight = scrollSize.y-clientSize.y;
  215. // // if (y+200>scrollHeight) {
  216. // // if (!_self.isElementLoaded) _self.listItemNext();
  217. // // }
  218. // }
  219. // });
  220. // }.bind(this));
  221. this.setScreenHeight();
  222. this.addEvent("resize", this.setScreenHeight.bind(this));
  223. },
  224. setScreenHeight: function(){
  225. var size = this.node.getSize();
  226. var toolbarSize = this.toolbarNode.getSize();
  227. var bottomSize = this.bottomNode.getSize();
  228. var y = size.y-toolbarSize.y-bottomSize.y;
  229. this.screenNode.setStyle("height", ""+y+"px");
  230. }
  231. });
  232. MWF.xApplication.LogViewer.Log = new Class({
  233. initialize: function(log, app){
  234. this.log = log;
  235. this.app = app;
  236. this.css = this.app.css;
  237. this.lp = this.app.lp;
  238. this.load();
  239. },
  240. load: function(){
  241. this.node = new Element("div", {"styles": this.css.logItemNode}).inject(this.app.screenInforAreaNode);
  242. var message = this.log.message + ((this.log.person) ? "&nbsp;("+this.log.person+")": "");
  243. var html = "<pre><span class='MWFLogCheckbox' style='cursor: pointer;float: left; height: 20px; width: 30px; background: url(/x_component_LogViewer/$Main/default/check.png) no-repeat center center'></span>" +
  244. "<span style='float: left;font-size: 14px; font-weight: bold; width: 160px; text-align: right'>"+this.log.occurTime+"</span>" +
  245. "<span style='float:left'>\t</span>" +
  246. "<span style='font-size: 14px; font-weight: bold;'>"+message+"</span><br/>";
  247. if (this.log.exceptionClass){
  248. html += "<span style='float: left; width: 190px; text-align: right; color: #6BC5FC;'>ExceptionClass: </span>" +
  249. "<span style='float:left'>\t</span>" +
  250. "<span>"+this.log.exceptionClass+"</span><br/>";
  251. }
  252. if (this.log.loggerName){
  253. html += "<span style='float: left; width: 190px; text-align: right; color: #6BC5FC;'>LoggerName: </span>" +
  254. "<span style='float:left'>\t</span>" +
  255. "<span>"+this.log.loggerName+"</span><br/>";
  256. }
  257. if (this.log.stackTrace){
  258. var traces = this.log.stackTrace.split(/\r\n\t/g);
  259. html += "<span class='MWFLogStackTrace'><span style='float: left; width: 190px; text-align: right; color: #6BC5FC;'>StackTrace: </span>" +
  260. "<span style='float:left'>\t</span>";
  261. if (traces.length>1) {
  262. html += "<span class='MWFLogStackTraceAction' style='float: left; cursor: pointer; height: 20px; width: 16px; background: url(/x_component_LogViewer/$Main/default/right.png) no-repeat left center'></span>";
  263. }
  264. html += "<span>"+traces[0]+"</span></span><br/>";
  265. // traces.each(function(trace, i){
  266. // if (i!==0){
  267. // html += "<span style='float: left; width: 190px; text-align: right; color: #6BC5FC;'>&nbsp;</span>" +
  268. // "<span>&nbsp;&nbsp;</span>" +
  269. // "<span>\t"+trace+"</span><br/>";
  270. // }
  271. // }.bind(this));
  272. }
  273. if (this.log.requestUrl){
  274. var request = ((this.log.requestMethod) ? this.log.requestMethod+"&nbsp;": "")+
  275. this.log.requestUrl+
  276. ((this.log.requestRemoteAddr) ? "&nbsp; From &nbsp;"+this.log.requestRemoteAddr : "");
  277. html += "<span class='MWFLogRequest'><span style='float: left; width: 190px; text-align: right; color: #6BC5FC;'>RequestInfor: </span>" +
  278. "<span style='float:left'>\t</span>";
  279. html += "<span class='MWFLogRequestAction' style='float: left;cursor: pointer; height: 20px; width: 16px; background: url(/x_component_LogViewer/$Main/default/right.png) no-repeat left center'></span>";
  280. html += "<span>"+request+"</span></span><br/>";
  281. }
  282. html += "</pre>";
  283. this.node.set("html", html);
  284. this.checkbox = this.node.getElement(".MWFLogCheckbox");
  285. this.traceNode = this.node.getElement(".MWFLogStackTrace");
  286. this.requestNode = this.node.getElement(".MWFLogRequest");
  287. this.traceActionNode = this.node.getElement(".MWFLogStackTraceAction");
  288. this.requestActionNode = this.node.getElement(".MWFLogRequestAction");
  289. this.setEvent();
  290. },
  291. setEvent: function(){
  292. this.node.addEvents({
  293. "mouseover": function(){ this.node.setStyles(this.css.logItemNode_over); }.bind(this),
  294. "mouseout": function(){ this.node.setStyles(this.css.logItemNode); }.bind(this)
  295. });
  296. if (this.checkbox){
  297. this.checkbox.addEvent("click", function(e){
  298. this.checkSelected();
  299. e.stopPropagation();
  300. }.bind(this))
  301. }
  302. if (this.traceActionNode){
  303. this.traceActionNode.addEvent("click", function(e){
  304. this.expandOrCollapseTrace();
  305. e.stopPropagation();
  306. }.bind(this))
  307. }
  308. if (this.requestActionNode){
  309. this.requestActionNode.addEvent("click", function(e){
  310. this.expandOrCollapseRequest();
  311. e.stopPropagation();
  312. }.bind(this))
  313. }
  314. },
  315. checkSelected: function(){
  316. var range = document.createRange();
  317. range.selectNode(this.node);
  318. var s = window.getSelection();
  319. s.selectAllChildren(this.node);
  320. },
  321. expandOrCollapseTrace: function(){
  322. if (this.log.stackTrace){
  323. if (!this.isTraceExpanded){
  324. this.expandedTrace();
  325. }else{
  326. this.collapseTrace();
  327. }
  328. }
  329. },
  330. expandedTrace: function(){
  331. if (!this.traceAllNode) this.createTraceAllNode();
  332. this.traceAllNode.setStyle("display", "inline");
  333. this.traceActionNode.setStyle("background-image", "url(/x_component_LogViewer/$Main/default/down.png)");
  334. this.isTraceExpanded = true;
  335. },
  336. collapseTrace: function(){
  337. if (this.traceAllNode){
  338. this.traceAllNode.destroy();
  339. this.traceAllNode = null;
  340. }
  341. this.traceActionNode.setStyle("background-image", "url(/x_component_LogViewer/$Main/default/right.png)");
  342. this.isTraceExpanded = false;
  343. },
  344. createTraceAllNode: function(){
  345. var brNode = this.traceNode.getNext();
  346. this.traceAllNode = new Element("span").inject(brNode, "after");
  347. var traces = this.log.stackTrace.split(/\r\n\t/g);
  348. var html = "";
  349. traces.each(function(t, i){
  350. if (i!==0){
  351. html += "<span style='float: left; width: 190px;'>\t</span>" +
  352. "<span>\t</span>" +
  353. "<span>\t"+t+"</span><br/>";
  354. }
  355. }.bind(this));
  356. this.traceAllNode.set("html", html);
  357. },
  358. expandOrCollapseRequest: function(){
  359. if (this.log.requestUrl){
  360. if (!this.isRequestExpanded){
  361. this.expandedRequest();
  362. }else{
  363. this.collapseRequest();
  364. }
  365. }
  366. },
  367. expandedRequest: function(){
  368. if (!this.requestAllNode) this.createRequestAllNode();
  369. this.requestAllNode.setStyle("display", "inline");
  370. this.requestActionNode.setStyle("background-image", "url(/x_component_LogViewer/$Main/default/down.png)");
  371. this.isRequestExpanded = true;
  372. },
  373. collapseRequest: function(){
  374. if (this.requestAllNode){
  375. this.requestAllNode.destroy();
  376. this.requestAllNode = null;
  377. }
  378. this.requestActionNode.setStyle("background-image", "url(/x_component_LogViewer/$Main/default/right.png)");
  379. this.isRequestExpanded = false;
  380. },
  381. createRequestAllNode: function(){
  382. var brNode = this.requestNode.getNext();
  383. this.requestAllNode = new Element("span").inject(brNode, "after");
  384. var html = "";
  385. html += "<span style='float: left; width: 190px;'>\t</span>" +
  386. "<span style='float: left;'>\t</span>" +
  387. "<span style='color: #6BC5FC; width: 108px;'>requestRemoteAddr: </span><span>"+(this.log.requestRemoteAddr || "&nbsp;")+"</span>&nbsp;&nbsp;" +
  388. "<span style='color: #6BC5FC; width: 108px;'>requestRemoteHost: </span><span>"+(this.log.requestRemoteHost || "&nbsp;")+"</span>&nbsp;&nbsp;" +
  389. "<span style='color: #6BC5FC; width: 108px;'>requestBodyLength: </span><span>"+(this.log.requestBodyLength || "&nbsp;")+"</span>" +
  390. "<br/>";
  391. // if (this.log.requestHead) html += "<span style='float: left; width: 190px;'>\t</span>" +
  392. // "<span style='float: left;'>\t</span>" +
  393. // "<span style='float: left; color: #6BC5FC; width: 108px;'>requestHead: </span><span style='word-break:break-all;'>"+this.log.requestHead+"</span><br/>";
  394. var headers = this.log.requestHead.split(/\n/g);
  395. headers.each(function(head, i){
  396. if (i===0){
  397. html += "<span style='float: left; width: 190px;'>\t</span>" +
  398. "<span style='float: left;'>\t</span>" +
  399. "<span style='float: left; color: #6BC5FC; width: 108px;'>requestHead: </span><span>"+head+"</span><br/>";
  400. }else{
  401. html += "<span style='float: left; width: 190px;'>\t</span>" +
  402. "<span style='float: left;'>\t</span>" +
  403. "<span style='float: left; color: #6BC5FC; width: 108px;'>\t</span><span>"+head+"</span><br/>";
  404. }
  405. }.bind(this));
  406. if (this.log.requestBody){
  407. var bodys = this.log.requestBody.split(/\n/g);
  408. bodys.each(function(body, i){
  409. if (i===0){
  410. html += "<span style='float: left; width: 190px;'>\t</span>" +
  411. "<span style='float: left;'>\t</span>" +
  412. "<span style='float: left; color: #6BC5FC; width: 108px;'>requestBody: </span><span>"+body+"</span><br/>";
  413. }else{
  414. html += "<span style='float: left; width: 190px;'>\t</span>" +
  415. "<span style='float: left;'>\t</span>" +
  416. "<span style='float: left; color: #6BC5FC; width: 108px;'>\t</span><span>"+body+"</span><br/>";
  417. }
  418. }.bind(this));
  419. }
  420. // requestHead
  421. // requestRemoteAddr
  422. // requestRemoteHost
  423. // requestBodyLength
  424. // requestBody
  425. this.requestAllNode.set("html", html);
  426. }
  427. });