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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* *************************************************************************
  2. IT Mill Toolkit
  3. Development of Browser User Intarfaces 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/license.txt. Use of this product might
  8. require purchasing a commercial license from IT Mill Ltd. For guidelines
  9. on usage, see license/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.web;
  19. /** <p>Class providing centralized logging services. The logger defines
  20. * five message types, and provides methods to create messages of those
  21. * types. These types are:</p>
  22. *
  23. * <ul>
  24. * <li> <code>info</code> - Useful information generated during normal
  25. * operation of the application
  26. * <li> <code>warning</code> - An error situation has occurred, but the
  27. * operation was able to finish succesfully
  28. * <li> <code>error</code> - An error situation which prevented the
  29. * operation from finishing succesfully
  30. * <li> <code>debug</code> - Internal information from the application meant
  31. * for developers
  32. * <li> <code>exception</code> - A Java exception reported using the logger.
  33. * Includes the exception stack trace and a possible free-form message
  34. * </ul>
  35. *
  36. * <p>Currently the class offers logging only to the standard output</p>
  37. *
  38. * @author IT Mill Ltd.
  39. * @version @VERSION@
  40. * @since 3.0
  41. */
  42. public class Log {
  43. private static boolean useStdOut = true;
  44. private static String LOG_MSG_INFO = "[INFO]";
  45. private static String LOG_MSG_ERROR = "[ERROR]";
  46. private static String LOG_MSG_WARN = "[WARNING]";
  47. private static String LOG_MSG_DEBUG = "[DEBUG]";
  48. private static String LOG_MSG_EXCEPT = "[EXCEPTION]";
  49. /** Logs a <code>warning</code> message.
  50. *
  51. * @param message Message <code>String</code> to be logged.
  52. */
  53. protected static synchronized void warn(java.lang.String message) {
  54. if (Log.useStdOut) System.out.println(LOG_MSG_WARN+ " "+message);
  55. }
  56. /** Logs a <code>debug</code> message.
  57. *
  58. * @param message Message <code>String</code> to be logged.
  59. */
  60. protected static synchronized void debug(java.lang.String message) {
  61. if (Log.useStdOut) System.out.println(LOG_MSG_DEBUG+ " "+message);
  62. }
  63. /** Logs an <code>info</code> message.
  64. *
  65. * @param message Message <code>String</code> to be logged.
  66. */
  67. protected static synchronized void info(java.lang.String message) {
  68. if (Log.useStdOut) System.out.println(LOG_MSG_INFO+ " "+message);
  69. }
  70. /** Logs a Java exception and an accompanying error message.
  71. *
  72. * @param message Message <code>String</code> to be logged.
  73. * @param e Exception to be logged.
  74. */
  75. protected static synchronized void except(java.lang.String message, Exception e) {
  76. if (Log.useStdOut) {
  77. System.out.println(LOG_MSG_EXCEPT+ " "+message);
  78. e.printStackTrace();
  79. }
  80. }
  81. /** Logs an <code>error</code> message.
  82. *
  83. * @param message Message <code>String</code> to be logged.
  84. */
  85. protected static synchronized void error(java.lang.String message) {
  86. if (Log.useStdOut) System.out.println(LOG_MSG_ERROR+ " "+message);
  87. }
  88. }