Improve logging
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 24 May 2010 11:52:49 +0000 (11:52 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 24 May 2010 11:52:49 +0000 (11:52 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@3591 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionThread.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThreadGroup.java [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/log4j/SlcExecutionAppender.java

index c81e8b1a0d64eecfa2b13bd5a2a3349d1024ed2a..db289b4a5c6bf878788e9ea5ff7d6a8fa7d566c2 100644 (file)
@@ -1,14 +1,9 @@
 package org.argeo.slc.core.execution;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.execution.ExecutionFlowDescriptor;
 import org.argeo.slc.process.RealizedFlow;
-import org.argeo.slc.process.SlcExecutionNotifier;
 import org.argeo.slc.process.SlcExecutionStep;
 
 /** Thread of a single execution */
@@ -63,15 +58,8 @@ public class ExecutionThread extends Thread {
                }
        }
 
-       public void dispatchAddStep(SlcExecutionStep step) {
-               processThread.getSlcProcess().getSteps().add(step);
-               List<SlcExecutionStep> steps = new ArrayList<SlcExecutionStep>();
-               steps.add(step);
-               for (Iterator<SlcExecutionNotifier> it = processThread
-                               .getExecutionModulesManager().getSlcExecutionNotifiers()
-                               .iterator(); it.hasNext();) {
-                       it.next().addSteps(processThread.getSlcProcess(), steps);
-               }
+       private void dispatchAddStep(SlcExecutionStep step) {
+               processThread.getProcessThreadGroup().dispatchAddStep(step);
        }
 
 }
index ec600cb5776deeaa6a9020cba225f2c284d59ea0..1987f259e9ef8c84d997f6ada6a0a0f0283cc638 100644 (file)
@@ -16,7 +16,7 @@ public class ProcessThread extends Thread {
 
        private final AbstractExecutionModulesManager executionModulesManager;
        private final SlcExecution slcProcess;
-       private final ThreadGroup processThreadGroup;
+       private final ProcessThreadGroup processThreadGroup;
        private final List<RealizedFlow> flowsToProcess = new ArrayList<RealizedFlow>();
 
        private Boolean hadAnError = false;
@@ -28,8 +28,7 @@ public class ProcessThread extends Thread {
                                "SLC Process #" + slcExecution.getUuid());
                this.executionModulesManager = executionModulesManager;
                this.slcProcess = slcExecution;
-               processThreadGroup = new ThreadGroup("SLC Process #"
-                               + slcExecution.getUuid() + " thread group");
+               processThreadGroup = new ProcessThreadGroup(this);
        }
 
        public void run() {
@@ -83,7 +82,7 @@ public class ProcessThread extends Thread {
                return slcProcess;
        }
 
-       public ThreadGroup getProcessThreadGroup() {
+       public ProcessThreadGroup getProcessThreadGroup() {
                return processThreadGroup;
        }
 
diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThreadGroup.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThreadGroup.java
new file mode 100644 (file)
index 0000000..7084f12
--- /dev/null
@@ -0,0 +1,35 @@
+package org.argeo.slc.core.execution;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.argeo.slc.process.SlcExecution;
+import org.argeo.slc.process.SlcExecutionNotifier;
+import org.argeo.slc.process.SlcExecutionStep;
+
+public class ProcessThreadGroup extends ThreadGroup {
+       private final ProcessThread processThread;
+
+       public ProcessThreadGroup(ProcessThread processThread) {
+               super("SLC Process #" + processThread.getSlcProcess().getUuid()
+                               + " thread group");
+               this.processThread = processThread;
+       }
+
+       public SlcExecution getSlcProcess() {
+               return processThread.getSlcProcess();
+       }
+
+       public void dispatchAddStep(SlcExecutionStep step) {
+               processThread.getSlcProcess().getSteps().add(step);
+               List<SlcExecutionStep> steps = new ArrayList<SlcExecutionStep>();
+               steps.add(step);
+               for (Iterator<SlcExecutionNotifier> it = processThread
+                               .getExecutionModulesManager().getSlcExecutionNotifiers()
+                               .iterator(); it.hasNext();) {
+                       it.next().addSteps(processThread.getSlcProcess(), steps);
+               }
+       }
+
+}
index 85d3e677c5853cff649d01f11cbced95ecdee2ec..e14a1f24f58922e7b61979694f679969aa87c0ce 100644 (file)
@@ -6,6 +6,7 @@ import org.apache.log4j.Logger;
 import org.apache.log4j.PatternLayout;
 import org.apache.log4j.spi.LoggingEvent;
 import org.argeo.slc.core.execution.ExecutionThread;
+import org.argeo.slc.core.execution.ProcessThreadGroup;
 import org.argeo.slc.process.SlcExecutionStep;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.InitializingBean;
@@ -16,6 +17,7 @@ public class SlcExecutionAppender extends AppenderSkeleton implements
 
        private Layout layout = null;
        private String pattern = "%m - %c%n";
+       private Boolean onlyExecutionThread = true;
 
        public void afterPropertiesSet() {
                if (layout != null)
@@ -27,13 +29,14 @@ public class SlcExecutionAppender extends AppenderSkeleton implements
 
        @Override
        protected void append(LoggingEvent event) {
-               if (!(Thread.currentThread() instanceof ExecutionThread))
-                       return;
-
-               ExecutionThread executionThread = (ExecutionThread) Thread
-                               .currentThread();
-               executionThread.dispatchAddStep(new SlcExecutionStep(layout
-                               .format(event)));
+               Thread currentThread = Thread.currentThread();
+               if (currentThread.getThreadGroup() instanceof ProcessThreadGroup) {
+                       if (onlyExecutionThread
+                                       && !(currentThread instanceof ExecutionThread))
+                               return;
+                       ((ProcessThreadGroup) currentThread.getThreadGroup())
+                                       .dispatchAddStep(new SlcExecutionStep(layout.format(event)));
+               }
        }
 
        public void destroy() throws Exception {
@@ -55,4 +58,8 @@ public class SlcExecutionAppender extends AppenderSkeleton implements
                this.pattern = pattern;
        }
 
+       public void setOnlyExecutionThread(Boolean onlyExecutionThread) {
+               this.onlyExecutionThread = onlyExecutionThread;
+       }
+
 }