package org.argeo.slc.log4j;
import java.util.Date;
+import java.util.concurrent.BlockingQueue;
import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.Layout;
import org.apache.log4j.Level;
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;
+import org.argeo.slc.execution.ExecutionStep;
/** Not meant to be used directly in standard log4j config */
-public class SlcExecutionAppender extends AppenderSkeleton implements
- InitializingBean, DisposableBean {
+public class SlcExecutionAppender extends AppenderSkeleton {
private Boolean disabled = false;
}
};
- private Layout layout = null;
- private String pattern = "%m - %c%n";
+ // private Layout layout = null;
+ // private String pattern = "%m - %c%n";
private Boolean onlyExecutionThread = false;
- public void afterPropertiesSet() {
- if (layout != null)
- setLayout(layout);
- else
- setLayout(new PatternLayout(pattern));
+ public void init() {
+ // if (layout != null)
+ // setLayout(layout);
+ // else
+ // setLayout(new PatternLayout(pattern));
Logger.getRootLogger().addAppender(this);
}
}
}
+ // Check whether we are within an executing process
Thread currentThread = Thread.currentThread();
if (currentThread.getThreadGroup() instanceof ProcessThreadGroup) {
if (onlyExecutionThread
final String type;
if (event.getLevel().equals(Level.ERROR)
|| event.getLevel().equals(Level.FATAL))
- type = SlcExecutionStep.ERROR;
+ type = ExecutionStep.ERROR;
else if (event.getLevel().equals(Level.WARN))
- type = SlcExecutionStep.WARNING;
+ type = ExecutionStep.WARNING;
else if (event.getLevel().equals(Level.INFO))
- type = SlcExecutionStep.INFO;
+ type = ExecutionStep.INFO;
else if (event.getLevel().equals(Level.DEBUG))
- type = SlcExecutionStep.DEBUG;
+ type = ExecutionStep.DEBUG;
else if (event.getLevel().equals(Level.TRACE))
- type = SlcExecutionStep.TRACE;
+ type = ExecutionStep.TRACE;
else
- type = SlcExecutionStep.INFO;
+ type = ExecutionStep.INFO;
- SlcExecutionStep step = new SlcExecutionStep(new Date(event
- .getTimeStamp()), type, layout.format(event));
+ ExecutionStep step = new ExecutionStep(event.getLoggerName(),
+ new Date(event.getTimeStamp()), type, event.getMessage()
+ .toString());
try {
dispatching.set(true);
- ((ProcessThreadGroup) currentThread.getThreadGroup())
- .dispatchAddStep(step);
+ BlockingQueue<ExecutionStep> steps = ((ProcessThreadGroup) currentThread
+ .getThreadGroup()).getSteps();
+ if (steps.remainingCapacity() == 0) {
+ stdOut("WARNING: execution steps queue is full, skipping step: "
+ + step);
+ // FIXME understand why it block indefinitely: the queue
+ // should be emptied by the logging thread
+ } else {
+ steps.add(step);
+ }
} finally {
dispatching.set(false);
}
return false;
}
- public void setLayout(Layout layout) {
- this.layout = layout;
- }
+ // public void setLayout(Layout layout) {
+ // this.layout = layout;
+ // }
- public void setPattern(String pattern) {
- this.pattern = pattern;
+ /** For development purpose, since using regular logging is not easy here */
+ static void stdOut(Object obj) {
+ System.out.println(obj);
}
+ // public void setPattern(String pattern) {
+ // this.pattern = pattern;
+ // }
+
public void setOnlyExecutionThread(Boolean onlyExecutionThread) {
this.onlyExecutionThread = onlyExecutionThread;
}