DefaultLogModule.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. * DefaultLogModule.java
  29. * ---------------------
  30. * (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
  31. *
  32. * Original Author: Thomas Morgner;
  33. * Contributor(s): David Gilbert (for Object Refinery Limited);
  34. *
  35. * $Id: DefaultLogModule.java,v 1.8 2005/12/18 23:29:18 taqua Exp $
  36. *
  37. * Changes
  38. * -------
  39. * 11-Jul-2003 : Initial version
  40. * 07-Jun-2004 : Added JCommon header (DG);
  41. * 25-Nov-2005 : The initialization was overly complicated. There is only
  42. * one logtarget here, and additional targets should create
  43. * an dependent module.
  44. */
  45. package org.jfree.base.log;
  46. import org.jfree.base.modules.AbstractModule;
  47. import org.jfree.base.modules.ModuleInitializeException;
  48. import org.jfree.base.modules.SubSystem;
  49. import org.jfree.util.Log;
  50. import org.jfree.util.PrintStreamLogTarget;
  51. /**
  52. * The module definition for the System.out-Logging. This is the default log
  53. * implementation and is provided to insert the logging initialisation in the
  54. * module loading process.
  55. *
  56. * @author Thomas Morgner
  57. */
  58. public class DefaultLogModule extends AbstractModule
  59. {
  60. /**
  61. * DefaultConstructor. Loads the module specification.
  62. *
  63. * @throws ModuleInitializeException if an error occured.
  64. */
  65. public DefaultLogModule() throws ModuleInitializeException
  66. {
  67. loadModuleInfo();
  68. }
  69. /**
  70. * Initalizes the module. This method initializes the logging system, if the
  71. * System.out logtarget is selected.
  72. *
  73. * @param subSystem the sub-system.
  74. * @throws ModuleInitializeException if an error occured.
  75. */
  76. public void initialize(final SubSystem subSystem)
  77. throws ModuleInitializeException
  78. {
  79. if (LogConfiguration.isDisableLogging())
  80. {
  81. return;
  82. }
  83. if (LogConfiguration.getLogTarget().equals
  84. (PrintStreamLogTarget.class.getName()))
  85. {
  86. DefaultLog.installDefaultLog();
  87. Log.getInstance().addTarget(new PrintStreamLogTarget());
  88. if ("true".equals(subSystem.getGlobalConfig().getConfigProperty
  89. ("org.jfree.base.LogAutoInit")))
  90. {
  91. Log.getInstance().init();
  92. }
  93. Log.info("Default log target started ... previous log messages " +
  94. "could have been ignored.");
  95. }
  96. }
  97. }