LogConfiguration.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* ========================================================================
  2. * JCommon : a free general purpose class library for the Java(tm) platform
  3. * ========================================================================
  4. *
  5. * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
  6. *
  7. * Project Info: http://www.jfree.org/jcommon/index.html
  8. *
  9. * This library is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  17. * License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  22. * USA.
  23. *
  24. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  25. * in the United States and other countries.]
  26. *
  27. * ---------------------
  28. * LogConfiguration.java
  29. * ---------------------
  30. * (C) Copyright 2004, by Object Refinery Limited.
  31. *
  32. * Original Author: Thomas Morgner;
  33. * Contributor(s): David Gilbert (for Object Refinery Limited);
  34. *
  35. * $Id: LogConfiguration.java,v 1.6 2005/12/18 23:29:18 taqua Exp $
  36. *
  37. * Changes
  38. * -------
  39. * 07-Jun-2004 : Added JCommon header (DG);
  40. *
  41. */
  42. package org.jfree.base.log;
  43. import org.jfree.base.BaseBoot;
  44. import org.jfree.util.PrintStreamLogTarget;
  45. /**
  46. * A log configuration class. This implementation is a simple frontend
  47. * to the global configuration.
  48. *
  49. * @author Thomas Morgner
  50. */
  51. public class LogConfiguration {
  52. /** The default 'disable logging' property value. */
  53. public static final String DISABLE_LOGGING_DEFAULT = "false";
  54. /** The 'log level' property key. */
  55. public static final String LOGLEVEL = "org.jfree.base.LogLevel";
  56. /** The default 'log level' property value. */
  57. public static final String LOGLEVEL_DEFAULT = "Info";
  58. /** The 'log target' property key. */
  59. public static final String LOGTARGET = "org.jfree.base.LogTarget";
  60. /** The default 'log target' property value. */
  61. public static final String LOGTARGET_DEFAULT =
  62. PrintStreamLogTarget.class.getName();
  63. /** The 'disable logging' property key. */
  64. public static final String DISABLE_LOGGING = "org.jfree.base.NoDefaultDebug";
  65. /**
  66. * Default constructor.
  67. */
  68. private LogConfiguration() {
  69. // nothing required.
  70. }
  71. /**
  72. * Returns the current log target.
  73. *
  74. * @return the log target.
  75. */
  76. public static String getLogTarget()
  77. {
  78. return BaseBoot.getInstance().getGlobalConfig().getConfigProperty
  79. (LOGTARGET, LOGTARGET_DEFAULT);
  80. }
  81. /**
  82. * Sets the log target.
  83. *
  84. * @param logTarget the new log target.
  85. */
  86. public static void setLogTarget(final String logTarget)
  87. {
  88. BaseBoot.getConfiguration().setConfigProperty (LOGTARGET, logTarget);
  89. }
  90. /**
  91. * Returns the log level.
  92. *
  93. * @return the log level.
  94. */
  95. public static String getLogLevel()
  96. {
  97. return BaseBoot.getInstance().getGlobalConfig().getConfigProperty
  98. (LOGLEVEL, LOGLEVEL_DEFAULT);
  99. }
  100. /**
  101. * Sets the log level, which is read from the global report configuration at
  102. * the point that the classloader loads the {@link org.jfree.util.Log} class.
  103. * <p>
  104. * Valid log levels are:
  105. *
  106. * <ul>
  107. * <li><code>"Error"</code> - error messages;</li>
  108. * <li><code>"Warn"</code> - warning messages;</li>
  109. * <li><code>"Info"</code> - information messages;</li>
  110. * <li><code>"Debug"</code> - debug messages;</li>
  111. * </ul>
  112. *
  113. * Notes:
  114. * <ul>
  115. * <li>the setting is not case sensitive.</li>
  116. * <li>changing the log level after the {@link org.jfree.util.Log} class has been
  117. * loaded will have no effect.</li>
  118. * <li>to turn of logging altogether, use the {@link #setDisableLogging} method.</li>
  119. * </ul>
  120. *
  121. * @param level the new log level.
  122. */
  123. public static void setLogLevel(final String level)
  124. {
  125. BaseBoot.getConfiguration().setConfigProperty(LOGLEVEL, level);
  126. }
  127. /**
  128. * Returns <code>true</code> if logging is disabled, and <code>false</code> otherwise.
  129. *
  130. * @return true, if logging is completly disabled, false otherwise.
  131. */
  132. public static boolean isDisableLogging()
  133. {
  134. return BaseBoot.getInstance().getGlobalConfig().getConfigProperty
  135. (DISABLE_LOGGING, DISABLE_LOGGING_DEFAULT).equalsIgnoreCase("true");
  136. }
  137. /**
  138. * Sets the flag that disables logging.
  139. * <p>
  140. * To switch off logging globally, you can use the following code:
  141. * <p>
  142. * <code>ReportConfiguration.getGlobalConfig().setDisableLogging(true);</code>
  143. *
  144. * @param disableLogging the flag.
  145. */
  146. public static void setDisableLogging(final boolean disableLogging)
  147. {
  148. BaseBoot.getConfiguration().setConfigProperty
  149. (DISABLE_LOGGING, String.valueOf(disableLogging));
  150. }
  151. }