Repository: incubator-nifi
Updated Branches:
  refs/heads/NIFI-250 7de30ab15 -> 767f37b83


NIFI-368: Extracted methods from ProcessorLog out to ComponentLog and made 
ProcessorLog extend from ComponentLog. This maintains backward compatibility 
while providing more generic loggers for other components


Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/8f78d619
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/8f78d619
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/8f78d619

Branch: refs/heads/NIFI-250
Commit: 8f78d619751c2bdb23f6c192a92716517922846a
Parents: 7de30ab
Author: Mark Payne <[email protected]>
Authored: Thu Feb 19 14:29:21 2015 -0500
Committer: Mark Payne <[email protected]>
Committed: Thu Feb 19 14:29:21 2015 -0500

----------------------------------------------------------------------
 .../controller/AbstractControllerService.java   |  13 ++-
 .../ControllerServiceInitializationContext.java |  10 ++
 .../org/apache/nifi/logging/ComponentLog.java   | 100 +++++++++++++++++++
 .../org/apache/nifi/logging/ProcessorLog.java   |  61 ++---------
 .../nifi/reporting/AbstractReportingTask.java   |  10 ++
 .../ReportingInitializationContext.java         |  10 ++
 6 files changed, 151 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/8f78d619/nifi/nifi-api/src/main/java/org/apache/nifi/controller/AbstractControllerService.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-api/src/main/java/org/apache/nifi/controller/AbstractControllerService.java
 
b/nifi/nifi-api/src/main/java/org/apache/nifi/controller/AbstractControllerService.java
index c12f2f8..71cdd23 100644
--- 
a/nifi/nifi-api/src/main/java/org/apache/nifi/controller/AbstractControllerService.java
+++ 
b/nifi/nifi-api/src/main/java/org/apache/nifi/controller/AbstractControllerService.java
@@ -22,6 +22,7 @@ import 
org.apache.nifi.components.AbstractConfigurableComponent;
 import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.components.PropertyValue;
 import org.apache.nifi.controller.annotation.OnConfigured;
+import org.apache.nifi.logging.ComponentLog;
 import org.apache.nifi.processor.ProcessorInitializationContext;
 import org.apache.nifi.reporting.InitializationException;
 
@@ -30,11 +31,13 @@ public abstract class AbstractControllerService extends 
AbstractConfigurableComp
     private String identifier;
     private ControllerServiceLookup serviceLookup;
     private volatile ConfigurationContext configContext;
-
+    private ComponentLog logger;
+    
     @Override
     public final void initialize(final ControllerServiceInitializationContext 
context) throws InitializationException {
         this.identifier = context.getIdentifier();
         serviceLookup = context.getControllerServiceLookup();
+        logger = context.getLogger();
         init(context);
     }
 
@@ -88,4 +91,12 @@ public abstract class AbstractControllerService extends 
AbstractConfigurableComp
      */
     protected void init(final ControllerServiceInitializationContext config) 
throws InitializationException {
     }
+    
+    /**
+     * Returns the logger that has been provided to the component by the 
framework in its initialize method.
+     * @return
+     */
+    protected ComponentLog getLogger() {
+        return logger;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/8f78d619/nifi/nifi-api/src/main/java/org/apache/nifi/controller/ControllerServiceInitializationContext.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-api/src/main/java/org/apache/nifi/controller/ControllerServiceInitializationContext.java
 
b/nifi/nifi-api/src/main/java/org/apache/nifi/controller/ControllerServiceInitializationContext.java
index b5b0412..d34c635 100644
--- 
a/nifi/nifi-api/src/main/java/org/apache/nifi/controller/ControllerServiceInitializationContext.java
+++ 
b/nifi/nifi-api/src/main/java/org/apache/nifi/controller/ControllerServiceInitializationContext.java
@@ -16,6 +16,8 @@
  */
 package org.apache.nifi.controller;
 
+import org.apache.nifi.logging.ComponentLog;
+
 public interface ControllerServiceInitializationContext {
 
     /**
@@ -33,4 +35,12 @@ public interface ControllerServiceInitializationContext {
      * @return
      */
     ControllerServiceLookup getControllerServiceLookup();
+    
+    /**
+     * Returns a logger that can be used to log important events in a standard 
way and generate
+     * bulletins when appropriate
+     * 
+     * @return
+     */
+    ComponentLog getLogger();
 }

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/8f78d619/nifi/nifi-api/src/main/java/org/apache/nifi/logging/ComponentLog.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-api/src/main/java/org/apache/nifi/logging/ComponentLog.java 
b/nifi/nifi-api/src/main/java/org/apache/nifi/logging/ComponentLog.java
new file mode 100644
index 0000000..c070e23
--- /dev/null
+++ b/nifi/nifi-api/src/main/java/org/apache/nifi/logging/ComponentLog.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.logging;
+
+
+/**
+ * <p>
+ * The ComponentLog provides a mechanism to ensure that all NiFi components 
are logging and reporting
+ * information in a consistent way. When messages are logged to the 
ComponentLog, each message has the
+ * following characteristics:
+ * </p>
+ * 
+ * <ul>
+ *  <li>
+ *      The <code>toString()</code> of the component is automatically 
prepended to the message so that it is clear
+ *      which component is providing the information. This is important, since 
a single component may have many
+ *      different instances within the same NiFi instance.
+ *  </li>
+ *  <li>
+ *      If the last value in an Object[] argument that is passed to the logger 
is a Throwable, then the logged message
+ *      will include a <code>toString()</code> of the Throwable; in addition, 
if the component's logger is set to
+ *      DEBUG level via the logback configuration, the Stacktrace will also be 
logged. This provides a mechanism to easily
+ *      enable stacktraces in the logs when they are desired without filling 
the logs with unneeded stack traces for messages
+ *      that end up occurring often.
+ *  </li>
+ *  <li>
+ *      Any message that is logged with a Severity level that meets or exceeds 
the configured Bulletin Level for that component
+ *      will also cause a Bulletin to be generated, so that the message is 
visible in the UI, allowing Dataflow Managers
+ *      to understand that a problem exists and what the issue is.
+ *  </li>
+ * </ul>
+ * 
+ */
+public interface ComponentLog {
+    void warn(String msg, Throwable t);
+
+    void warn(String msg, Object[] os);
+
+    void warn(String msg, Object[] os, Throwable t);
+
+    void warn(String msg);
+
+    void trace(String msg, Throwable t);
+
+    void trace(String msg, Object[] os);
+
+    void trace(String msg);
+
+    void trace(String msg, Object[] os, Throwable t);
+
+    boolean isWarnEnabled();
+
+    boolean isTraceEnabled();
+
+    boolean isInfoEnabled();
+
+    boolean isErrorEnabled();
+
+    boolean isDebugEnabled();
+
+    void info(String msg, Throwable t);
+
+    void info(String msg, Object[] os);
+
+    void info(String msg);
+
+    void info(String msg, Object[] os, Throwable t);
+
+    String getName();
+
+    void error(String msg, Throwable t);
+
+    void error(String msg, Object[] os);
+
+    void error(String msg);
+
+    void error(String msg, Object[] os, Throwable t);
+
+    void debug(String msg, Throwable t);
+
+    void debug(String msg, Object[] os);
+
+    void debug(String msg, Object[] os, Throwable t);
+
+    void debug(String msg);
+}

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/8f78d619/nifi/nifi-api/src/main/java/org/apache/nifi/logging/ProcessorLog.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-api/src/main/java/org/apache/nifi/logging/ProcessorLog.java 
b/nifi/nifi-api/src/main/java/org/apache/nifi/logging/ProcessorLog.java
index c5fa7b1..0d66d85 100644
--- a/nifi/nifi-api/src/main/java/org/apache/nifi/logging/ProcessorLog.java
+++ b/nifi/nifi-api/src/main/java/org/apache/nifi/logging/ProcessorLog.java
@@ -16,58 +16,15 @@
  */
 package org.apache.nifi.logging;
 
-public interface ProcessorLog {
 
-    void warn(String msg, Throwable t);
-
-    void warn(String msg, Object[] os);
-
-    void warn(String msg, Object[] os, Throwable t);
-
-    void warn(String msg);
-
-    void trace(String msg, Throwable t);
-
-    void trace(String msg, Object[] os);
-
-    void trace(String msg);
-
-    void trace(String msg, Object[] os, Throwable t);
-
-    boolean isWarnEnabled();
-
-    boolean isTraceEnabled();
-
-    boolean isInfoEnabled();
-
-    boolean isErrorEnabled();
-
-    boolean isDebugEnabled();
-
-    void info(String msg, Throwable t);
-
-    void info(String msg, Object[] os);
-
-    void info(String msg);
-
-    void info(String msg, Object[] os, Throwable t);
-
-    String getName();
-
-    void error(String msg, Throwable t);
-
-    void error(String msg, Object[] os);
-
-    void error(String msg);
-
-    void error(String msg, Object[] os, Throwable t);
-
-    void debug(String msg, Throwable t);
-
-    void debug(String msg, Object[] os);
-
-    void debug(String msg, Object[] os, Throwable t);
-
-    void debug(String msg);
+/**
+ * The ProcessorLog is an extension of ComponentLog but provides no additional 
functionality.
+ * It exists because ProcessorLog was created first,
+ * but when Controller Services and Reporting Tasks began to be used more 
heavily loggers
+ * were needed for them as well. We did not want to return a ProcessorLog to a 
ControllerService
+ * or a ReportingTask, so all of the methods were moved to a higher interface 
named ComponentLog.
+ * However, we kept the ProcessorLog interface around in order to maintain 
backward compatibility.
+ */
+public interface ProcessorLog extends ComponentLog {
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/8f78d619/nifi/nifi-api/src/main/java/org/apache/nifi/reporting/AbstractReportingTask.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-api/src/main/java/org/apache/nifi/reporting/AbstractReportingTask.java
 
b/nifi/nifi-api/src/main/java/org/apache/nifi/reporting/AbstractReportingTask.java
index 5ed8f24..efcf2a3 100644
--- 
a/nifi/nifi-api/src/main/java/org/apache/nifi/reporting/AbstractReportingTask.java
+++ 
b/nifi/nifi-api/src/main/java/org/apache/nifi/reporting/AbstractReportingTask.java
@@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.nifi.components.AbstractConfigurableComponent;
 import org.apache.nifi.controller.ControllerServiceLookup;
+import org.apache.nifi.logging.ComponentLog;
 import org.apache.nifi.processor.ProcessorInitializationContext;
 
 public abstract class AbstractReportingTask extends 
AbstractConfigurableComponent implements ReportingTask {
@@ -28,10 +29,12 @@ public abstract class AbstractReportingTask extends 
AbstractConfigurableComponen
     private String name;
     private long schedulingNanos;
     private ControllerServiceLookup serviceLookup;
+    private ComponentLog logger;
 
     @Override
     public final void initialize(final ReportingInitializationContext config) 
throws InitializationException {
         identifier = config.getIdentifier();
+        logger = config.getLogger();
         name = config.getName();
         schedulingNanos = config.getSchedulingPeriod(TimeUnit.NANOSECONDS);
         serviceLookup = config.getControllerServiceLookup();
@@ -91,4 +94,11 @@ public abstract class AbstractReportingTask extends 
AbstractConfigurableComponen
     protected void init(final ReportingInitializationContext config) throws 
InitializationException {
     }
 
+    /**
+     * Returns the logger that has been provided to the component by the 
framework in its initialize method.
+     * @return
+     */
+    protected ComponentLog getLogger() {
+        return logger;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/8f78d619/nifi/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingInitializationContext.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingInitializationContext.java
 
b/nifi/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingInitializationContext.java
index a0ae88e..6b84589 100644
--- 
a/nifi/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingInitializationContext.java
+++ 
b/nifi/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingInitializationContext.java
@@ -19,6 +19,7 @@ package org.apache.nifi.reporting;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.nifi.controller.ControllerServiceLookup;
+import org.apache.nifi.logging.ComponentLog;
 import org.apache.nifi.scheduling.SchedulingStrategy;
 
 /**
@@ -77,4 +78,13 @@ public interface ReportingInitializationContext {
      * @return
      */
     SchedulingStrategy getSchedulingStrategy();
+    
+    
+    /**
+     * Returns a logger that can be used to log important events in a standard 
way and generate
+     * bulletins when appropriate
+     * 
+     * @return
+     */
+    ComponentLog getLogger();
 }

Reply via email to