You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VConsole.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2011 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client;
  17. import java.util.Set;
  18. import com.google.gwt.core.client.GWT;
  19. /**
  20. * A helper class to do some client side logging.
  21. * <p>
  22. * This class replaces previously used loggin style:
  23. * ApplicationConnection.getConsole().log("foo").
  24. * <p>
  25. * The default widgetset provides three modes for debugging:
  26. * <ul>
  27. * <li>NullConsole (Default, displays no errors at all)
  28. * <li>VDebugConsole ( Enabled by appending ?debug to url. Displays a floating
  29. * console in the browser and also prints to browsers internal console (builtin
  30. * or Firebug) and GWT's development mode console if available.)
  31. * <li>VDebugConsole in quiet mode (Enabled by appending ?debug=quiet. Same as
  32. * previous but without the console floating over application).
  33. * </ul>
  34. * <p>
  35. * Implementations can be customized with GWT deferred binding by overriding
  36. * NullConsole.class or VDebugConsole.class. This way developer can for example
  37. * build mechanism to send client side logging data to a server.
  38. * <p>
  39. * Note that logging in client side is not fully optimized away even in
  40. * production mode. Use logging moderately in production code to keep the size
  41. * of client side engine small. An exception is {@link GWT#log(String)} style
  42. * logging, which is available only in GWT development mode, but optimized away
  43. * when compiled to web mode.
  44. *
  45. *
  46. * TODO improve javadocs of individual methods
  47. *
  48. */
  49. public class VConsole {
  50. private static Console impl;
  51. /**
  52. * Used by ApplicationConfiguration to initialize VConsole.
  53. *
  54. * @param console
  55. */
  56. static void setImplementation(Console console) {
  57. impl = console;
  58. }
  59. /**
  60. * Used by ApplicationConnection to support deprecated getConsole() api.
  61. */
  62. static Console getImplementation() {
  63. return impl;
  64. }
  65. public static void log(String msg) {
  66. if (impl != null) {
  67. impl.log(msg);
  68. }
  69. }
  70. public static void log(Throwable e) {
  71. if (impl != null) {
  72. impl.log(e);
  73. }
  74. }
  75. public static void error(Throwable e) {
  76. if (impl != null) {
  77. impl.error(e);
  78. }
  79. }
  80. public static void error(String msg) {
  81. if (impl != null) {
  82. impl.error(msg);
  83. }
  84. }
  85. public static void printObject(Object msg) {
  86. if (impl != null) {
  87. impl.printObject(msg);
  88. }
  89. }
  90. public static void dirUIDL(ValueMap u, ApplicationConnection client) {
  91. if (impl != null) {
  92. impl.dirUIDL(u, client);
  93. }
  94. }
  95. public static void printLayoutProblems(ValueMap meta,
  96. ApplicationConnection applicationConnection,
  97. Set<ComponentConnector> zeroHeightComponents,
  98. Set<ComponentConnector> zeroWidthComponents) {
  99. if (impl != null) {
  100. impl.printLayoutProblems(meta, applicationConnection,
  101. zeroHeightComponents, zeroWidthComponents);
  102. }
  103. }
  104. }