From c64d43ec6b73af879e69af99b11620459159a96a Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 09 Mar 2012 14:44:59 +0000
Subject: [PATCH] Fix OPENDJ-438: Reduce verbosity of server.out during startup

---
 opends/src/server/org/opends/server/core/DirectoryServer.java                   |    2 
 opends/src/server/org/opends/server/tools/VerifyIndex.java                      |    2 
 opends/src/server/org/opends/server/tools/ExportLDIF.java                       |    9 ++--
 opends/src/server/org/opends/server/loggers/TextErrorLogPublisher.java          |   47 ++++++++++++++++++-----
 opends/src/server/org/opends/server/tools/RestoreDB.java                        |    9 ++--
 opends/src/server/org/opends/server/tools/RebuildIndex.java                     |    2 
 opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java  |    5 +-
 opends/src/server/org/opends/server/tools/BackUpDB.java                         |    9 ++--
 opends/src/quicksetup/org/opends/quicksetup/util/InProcessServerController.java |   11 +----
 opends/src/server/org/opends/server/tools/ImportLDIF.java                       |    4 +-
 10 files changed, 62 insertions(+), 38 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/util/InProcessServerController.java b/opends/src/quicksetup/org/opends/quicksetup/util/InProcessServerController.java
index 60b8e84..60acb7e 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/util/InProcessServerController.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/util/InProcessServerController.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2008-2010 Sun Microsystems, Inc.
+ *      Portions copyright 2012 ForgeRock AS.
  */
 
 package org.opends.quicksetup.util;
@@ -571,8 +572,8 @@
               TextDebugLogPublisher.getStartupTextDebugPublisher(debugWriter);
       DebugLogger.addDebugLogPublisher(startupDebugPublisher);
 
-      startupErrorPublisher =
-              TextErrorLogPublisher.getStartupTextErrorPublisher(errorWriter);
+      startupErrorPublisher = TextErrorLogPublisher
+          .getServerStartupTextErrorPublisher(errorWriter);
       ErrorLogger.addErrorLogPublisher(startupErrorPublisher);
 
       startupAccessPublisher =
@@ -586,12 +587,6 @@
     }
   }
 
-  static private void unregisterListenersForOutput() {
-    DebugLogger.removeDebugLogPublisher(startupDebugPublisher);
-    ErrorLogger.removeErrorLogPublisher(startupErrorPublisher);
-    AccessLogger.removeAccessLogPublisher(startupAccessPublisher);
-  }
-
   /**
    * Compares two lists of attributes for equality.  Any non-user attributes
    * are ignored during comparison.
diff --git a/opends/src/server/org/opends/server/core/DirectoryServer.java b/opends/src/server/org/opends/server/core/DirectoryServer.java
index fb15896..56bf2a4 100644
--- a/opends/src/server/org/opends/server/core/DirectoryServer.java
+++ b/opends/src/server/org/opends/server/core/DirectoryServer.java
@@ -9459,7 +9459,7 @@
     // Install the default loggers so the startup messages
     // will be printed.
     TextErrorLogPublisher startupErrorLogPublisher =
-        TextErrorLogPublisher.getStartupTextErrorPublisher(
+        TextErrorLogPublisher.getServerStartupTextErrorPublisher(
             new TextWriter.STDOUT());
     ErrorLogger.addErrorLogPublisher(startupErrorLogPublisher);
 
diff --git a/opends/src/server/org/opends/server/loggers/TextErrorLogPublisher.java b/opends/src/server/org/opends/server/loggers/TextErrorLogPublisher.java
index 2a96df8..7898a03 100644
--- a/opends/src/server/org/opends/server/loggers/TextErrorLogPublisher.java
+++ b/opends/src/server/org/opends/server/loggers/TextErrorLogPublisher.java
@@ -62,28 +62,53 @@
 
   private FileBasedErrorLogPublisherCfg currentConfig;
 
+
+
   /**
-   * Returns an instance of the text error log publisher that will print
-   * all messages to the provided writer. This is used to print the messages
-   * to the console when the server starts up.
+   * Returns a new text error log publisher which will print all messages to the
+   * provided writer. This publisher should be used by tools.
    *
-   * @param writer The text writer where the message will be written to.
-   * @return The instance of the text error log publisher that will print
-   * all messages to standard out.
+   * @param writer
+   *          The text writer where the message will be written to.
+   * @return A new text error log publisher which will print all messages to the
+   *         provided writer.
    */
-  public static TextErrorLogPublisher
-  getStartupTextErrorPublisher(TextWriter writer)
+  public static TextErrorLogPublisher getToolStartupTextErrorPublisher(
+      TextWriter writer)
+  {
+    TextErrorLogPublisher startupPublisher = new TextErrorLogPublisher();
+    startupPublisher.writer = writer;
+    startupPublisher.defaultSeverities.addAll(Arrays.asList(Severity.values()));
+    return startupPublisher;
+  }
+
+
+
+  /**
+   * Returns a new text error log publisher which will print only notices,
+   * severe warnings and errors, and fatal errors messages to the provided
+   * writer. This less verbose publisher should be used by the directory server
+   * during startup.
+   *
+   * @param writer
+   *          The text writer where the message will be written to.
+   * @return A new text error log publisher which will print only notices,
+   *         severe warnings and errors, and fatal errors messages to the
+   *         provided writer.
+   */
+  public static TextErrorLogPublisher getServerStartupTextErrorPublisher(
+      TextWriter writer)
   {
     TextErrorLogPublisher startupPublisher = new TextErrorLogPublisher();
     startupPublisher.writer = writer;
     startupPublisher.defaultSeverities.addAll(Arrays.asList(
-        Severity.FATAL_ERROR,
-        Severity.SEVERE_ERROR,
-        Severity.SEVERE_WARNING,
+        Severity.FATAL_ERROR, Severity.SEVERE_ERROR, Severity.SEVERE_WARNING,
         Severity.NOTICE));
     return startupPublisher;
   }
 
+
+
   /**
    * {@inheritDoc}
    */
diff --git a/opends/src/server/org/opends/server/tools/BackUpDB.java b/opends/src/server/org/opends/server/tools/BackUpDB.java
index cd5a1d6..4e38668 100644
--- a/opends/src/server/org/opends/server/tools/BackUpDB.java
+++ b/opends/src/server/org/opends/server/tools/BackUpDB.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2006-2009 Sun Microsystems, Inc.
+ *      Portions copyright 2012 ForgeRock AS.
  */
 package org.opends.server.tools;
 import org.opends.messages.Message;
@@ -539,7 +540,7 @@
   /**
    * {@inheritDoc}
    */
-  public Class getTaskClass() {
+  public Class<?> getTaskClass() {
     return BackupTask.class;
   }
 
@@ -714,10 +715,10 @@
 
       try
       {
-        ErrorLogPublisher errorLogPublisher =
-            TextErrorLogPublisher.getStartupTextErrorPublisher(
+        ErrorLogPublisher<?> errorLogPublisher =
+            TextErrorLogPublisher.getToolStartupTextErrorPublisher(
             new TextWriter.STREAM(out));
-        DebugLogPublisher debugLogPublisher =
+        DebugLogPublisher<?> debugLogPublisher =
             TextDebugLogPublisher.getStartupTextDebugPublisher(
             new TextWriter.STREAM(out));
         ErrorLogger.addErrorLogPublisher(errorLogPublisher);
diff --git a/opends/src/server/org/opends/server/tools/ExportLDIF.java b/opends/src/server/org/opends/server/tools/ExportLDIF.java
index ee5538c..a7e790b 100644
--- a/opends/src/server/org/opends/server/tools/ExportLDIF.java
+++ b/opends/src/server/org/opends/server/tools/ExportLDIF.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2006-2009 Sun Microsystems, Inc.
+ *      Portions copyright 2012 ForgeRock AS.
  */
 package org.opends.server.tools;
 
@@ -497,7 +498,7 @@
   /**
    * {@inheritDoc}
    */
-  public Class getTaskClass() {
+  public Class<?> getTaskClass() {
     return ExportTask.class;
   }
 
@@ -631,10 +632,10 @@
 
       try
       {
-        ErrorLogPublisher errorLogPublisher =
-            TextErrorLogPublisher.getStartupTextErrorPublisher(
+        ErrorLogPublisher<?> errorLogPublisher =
+            TextErrorLogPublisher.getToolStartupTextErrorPublisher(
             new TextWriter.STREAM(out));
-        DebugLogPublisher debugLogPublisher =
+        DebugLogPublisher<?> debugLogPublisher =
             TextDebugLogPublisher.getStartupTextDebugPublisher(
             new TextWriter.STREAM(out));
         ErrorLogger.addErrorLogPublisher(errorLogPublisher);
diff --git a/opends/src/server/org/opends/server/tools/ImportLDIF.java b/opends/src/server/org/opends/server/tools/ImportLDIF.java
index 63ce0ea..3414aa2 100644
--- a/opends/src/server/org/opends/server/tools/ImportLDIF.java
+++ b/opends/src/server/org/opends/server/tools/ImportLDIF.java
@@ -23,7 +23,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions copyright 2011 ForgeRock AS.
+ *      Portions copyright 2011-2012 ForgeRock AS.
  */
 package org.opends.server.tools;
 
@@ -865,7 +865,7 @@
         try
         {
           ErrorLogPublisher<?> errorLogPublisher =
-              TextErrorLogPublisher.getStartupTextErrorPublisher(
+              TextErrorLogPublisher.getToolStartupTextErrorPublisher(
                   new TextWriter.STREAM(out));
           ErrorLogger.addErrorLogPublisher(errorLogPublisher);
         }
diff --git a/opends/src/server/org/opends/server/tools/RebuildIndex.java b/opends/src/server/org/opends/server/tools/RebuildIndex.java
index b5804ff..d789ffc 100644
--- a/opends/src/server/org/opends/server/tools/RebuildIndex.java
+++ b/opends/src/server/org/opends/server/tools/RebuildIndex.java
@@ -430,7 +430,7 @@
       try
       {
         ErrorLogPublisher<?> errorLogPublisher =
-            TextErrorLogPublisher.getStartupTextErrorPublisher(
+            TextErrorLogPublisher.getToolStartupTextErrorPublisher(
             new TextWriter.STREAM(out));
         DebugLogPublisher<?> debugLogPublisher =
             TextDebugLogPublisher.getStartupTextDebugPublisher(
diff --git a/opends/src/server/org/opends/server/tools/RestoreDB.java b/opends/src/server/org/opends/server/tools/RestoreDB.java
index 5269a48..8e10368 100644
--- a/opends/src/server/org/opends/server/tools/RestoreDB.java
+++ b/opends/src/server/org/opends/server/tools/RestoreDB.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2006-2009 Sun Microsystems, Inc.
+ *      Portions copyright 2012 ForgeRock AS.
  */
 package org.opends.server.tools;
 import org.opends.messages.Message;
@@ -328,7 +329,7 @@
   /**
    * {@inheritDoc}
    */
-  public Class getTaskClass() {
+  public Class<?> getTaskClass() {
     return RestoreTask.class;
   }
 
@@ -462,10 +463,10 @@
 
       try
       {
-        ErrorLogPublisher errorLogPublisher =
-            TextErrorLogPublisher.getStartupTextErrorPublisher(
+        ErrorLogPublisher<?> errorLogPublisher =
+            TextErrorLogPublisher.getToolStartupTextErrorPublisher(
             new TextWriter.STREAM(out));
-        DebugLogPublisher debugLogPublisher =
+        DebugLogPublisher<?> debugLogPublisher =
             TextDebugLogPublisher.getStartupTextDebugPublisher(
             new TextWriter.STREAM(out));
         ErrorLogger.addErrorLogPublisher(errorLogPublisher);
diff --git a/opends/src/server/org/opends/server/tools/VerifyIndex.java b/opends/src/server/org/opends/server/tools/VerifyIndex.java
index 6f6a8f1..10bdf66 100644
--- a/opends/src/server/org/opends/server/tools/VerifyIndex.java
+++ b/opends/src/server/org/opends/server/tools/VerifyIndex.java
@@ -378,7 +378,7 @@
       try
       {
         ErrorLogPublisher<?> errorLogPublisher =
-            TextErrorLogPublisher.getStartupTextErrorPublisher(
+            TextErrorLogPublisher.getToolStartupTextErrorPublisher(
             new TextWriter.STREAM(out));
         DebugLogPublisher<?> debugLogPublisher =
             TextDebugLogPublisher.getStartupTextDebugPublisher(
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
index a06e1cd..08ea341 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -23,7 +23,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2011 ForgeRock AS
+ *      Portions Copyright 2011-2012 ForgeRock AS
  */
 package org.opends.server;
 
@@ -525,8 +525,9 @@
           TextAccessLogPublisher.getStartupTextAccessPublisher(
               ACCESS_TEXT_WRITER, false));
 
+      // Use more verbose tool logger.
       ErrorLogger.addErrorLogPublisher(
-         TextErrorLogPublisher.getStartupTextErrorPublisher(
+         TextErrorLogPublisher.getToolStartupTextErrorPublisher(
               ERROR_TEXT_WRITER));
 
       DebugLogger.addDebugLogPublisher(

--
Gitblit v1.10.0