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.

Log.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* *************************************************************************
  2. IT Mill Toolkit
  3. Development of Browser User Interfaces Made Easy
  4. Copyright (C) 2000-2006 IT Mill Ltd
  5. *************************************************************************
  6. This product is distributed under commercial license that can be found
  7. from the product package on license.pdf. Use of this product might
  8. require purchasing a commercial license from IT Mill Ltd. For guidelines
  9. on usage, see licensing-guidelines.html
  10. *************************************************************************
  11. For more information, contact:
  12. IT Mill Ltd phone: +358 2 4802 7180
  13. Ruukinkatu 2-4 fax: +358 2 4802 7181
  14. 20540, Turku email: info@itmill.com
  15. Finland company www: www.itmill.com
  16. Primary source for information and releases: www.itmill.com
  17. ********************************************************************** */
  18. package com.itmill.toolkit.terminal.gwt.server;
  19. /**
  20. * <p>
  21. * Class providing centralized logging services. The logger defines five message
  22. * types, and provides methods to create messages of those types. These types
  23. * are:
  24. * </p>
  25. *
  26. * <ul>
  27. * <li> <code>info</code> - Useful information generated during normal
  28. * operation of the application.
  29. * <li> <code>warning</code> - An error situation has occurred, but the
  30. * operation was able to finish succesfully.
  31. * <li> <code>error</code> - An error situation which prevented the operation
  32. * from finishing succesfully.
  33. * <li> <code>debug</code> - Internal information from the application meant
  34. * for developers.
  35. * <li> <code>exception</code> - A Java exception reported using the logger.
  36. * Includes the exception stack trace and a possible free-form message.
  37. * </ul>
  38. *
  39. * <p>
  40. * Currently the class offers logging only to the standard output.
  41. * </p>
  42. *
  43. * @author IT Mill Ltd.
  44. * @version
  45. * @VERSION@
  46. * @since 5.0
  47. */
  48. class Log {
  49. private static boolean useStdOut = true;
  50. private static String LOG_MSG_INFO = "[INFO]";
  51. private static String LOG_MSG_ERROR = "[ERROR]";
  52. private static String LOG_MSG_WARN = "[WARNING]";
  53. private static String LOG_MSG_DEBUG = "[DEBUG]";
  54. private static String LOG_MSG_EXCEPT = "[EXCEPTION]";
  55. /**
  56. * Logs the <code>warning</code> message.
  57. *
  58. * @param message
  59. * the Message String to be logged.
  60. */
  61. static synchronized void warn(java.lang.String message) {
  62. if (Log.useStdOut)
  63. System.out.println(LOG_MSG_WARN + " " + message);
  64. }
  65. /**
  66. * Logs the <code>debug</code> message.
  67. *
  68. * @param message
  69. * the Message String to be logged.
  70. */
  71. static synchronized void debug(java.lang.String message) {
  72. if (Log.useStdOut)
  73. System.out.println(LOG_MSG_DEBUG + " " + message);
  74. }
  75. /**
  76. * Logs an <code>info</code> message.
  77. *
  78. * @param message
  79. * the Message String to be logged.
  80. */
  81. static synchronized void info(java.lang.String message) {
  82. if (Log.useStdOut)
  83. System.out.println(LOG_MSG_INFO + " " + message);
  84. }
  85. /**
  86. * Logs the Java exception and an accompanying error message.
  87. *
  88. * @param message
  89. * the Message String to be logged.
  90. * @param e
  91. * the Exception to be logged.
  92. */
  93. static synchronized void except(java.lang.String message, Exception e) {
  94. if (Log.useStdOut) {
  95. System.out.println(LOG_MSG_EXCEPT + " " + message);
  96. e.printStackTrace();
  97. }
  98. }
  99. /**
  100. * Logs the <code>error</code> message.
  101. *
  102. * @param message
  103. * the Message String to be logged.
  104. */
  105. static synchronized void error(java.lang.String message) {
  106. if (Log.useStdOut)
  107. System.out.println(LOG_MSG_ERROR + " " + message);
  108. }
  109. }