PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/qooxdoo/component/inspector/source/class/inspector/console/Appender.js

https://github.com/Wkasel/qooxdoo
JavaScript | 127 lines | 74 code | 13 blank | 40 comment | 24 complexity | 5d25fd6a17dfa4b7aca67f8540131c52 MD5 | raw file
  1. /* ************************************************************************
  2. qooxdoo - the new era of web development
  3. http://qooxdoo.org
  4. Copyright:
  5. 2007 - 2009 1&1 Internet AG, Germany, http://www.1and1.org
  6. License:
  7. LGPL: http://www.gnu.org/licenses/lgpl.html
  8. EPL: http://www.eclipse.org/org/documents/epl-v10.php
  9. See the LICENSE file in the project's top-level directory for details.
  10. Authors:
  11. * Christian Hagendorn (chris_schmidt)
  12. ************************************************************************ */
  13. /**
  14. * Appender for logging the Iframe.
  15. */
  16. qx.Class.define("inspector.console.Appender", {
  17. statics :
  18. {
  19. consoleView : null,
  20. /**
  21. * Processes a single log entry
  22. *
  23. * @signature function(entry)
  24. * @param entry {Map} The entry to process
  25. * @return {void}
  26. */
  27. process : function(entry)
  28. {
  29. if (this.consoleView && !qx.core.ObjectRegistry.inShutDown)
  30. {
  31. var text = this.__toText(entry);
  32. if (entry.level == "info") {
  33. this.consoleView.info(text);
  34. } else if (entry.level == "warn") {
  35. this.consoleView.warn(text);
  36. } else if (entry.level == "error") {
  37. this.consoleView.error(text);
  38. } else {
  39. this.consoleView.debug(text);
  40. }
  41. }
  42. },
  43. /**
  44. * Convert the log entry to a string value.
  45. *
  46. * @param entry {Map} The log entry.
  47. * @return {string} Entry as string value.
  48. */
  49. __toText : function(entry)
  50. {
  51. var iFrameWindow = qx.core.Init.getApplication().getIframeWindowObject();
  52. var output = new qx.util.StringBuilder();
  53. var item, msg, sub, list;
  54. output.add(entry.offset, "ms ");
  55. if (entry.object)
  56. {
  57. var obj = iFrameWindow.qx.core.ObjectRegistry.fromHashCode(entry.object);
  58. if (obj) {
  59. output.add(obj.classname, "[", obj.$$hash, "]: ");
  60. }
  61. }
  62. else if (entry.clazz)
  63. {
  64. output.add(entry.clazz.classname, ": ");
  65. }
  66. var items = entry.items;
  67. for (var i=0, il=items.length; i<il; i++)
  68. {
  69. item = items[i];
  70. msg = item.text;
  71. if (msg instanceof iFrameWindow.Array)
  72. {
  73. var list = [];
  74. for (var j=0, jl=msg.length; j<jl; j++)
  75. {
  76. sub = msg[j];
  77. if (typeof sub === "string") {
  78. list.push(this.__escapeHTML(sub));
  79. } else if (sub.key) {
  80. list.push(sub.key + ": " + this.__escapeHTML(sub.text));
  81. } else {
  82. list.push(this.__escapeHTML(sub.text));
  83. }
  84. }
  85. if (item.type === "map") {
  86. output.add("{ ", list.join(", "), " }");
  87. } else {
  88. output.add("[ ", list.join(", "), " ]");
  89. }
  90. }
  91. else
  92. {
  93. output.add(this.__escapeHTML(msg));
  94. }
  95. }
  96. return output.get();
  97. },
  98. /**
  99. * Escape the string value to HTML.
  100. *
  101. * @param value {String} value to escape
  102. * @return {String} escaped Value.
  103. */
  104. __escapeHTML : function(value) {
  105. return this.consoleView._console.escapeHtml(value);
  106. }
  107. }
  108. });