Permalink
Browse files

Audit log of Weasis usage

  • Loading branch information...
1 parent 1a9e88c commit cfbd982afdb9ed5dfeaf3a1259db5e3285770299 @nroduit committed Jul 10, 2012
Showing with 162 additions and 61 deletions.
  1. +5 −1 weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/util/ComboItemListener.java
  2. +3 −0 weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/util/SliderChangeListener.java
  3. +7 −0 weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/util/ToggleButtonListener.java
  4. +47 −0 weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/internal/Activator.java
  5. +2 −0 weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/media/data/MediaSeries.java
  6. +4 −0 weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/media/data/Series.java
  7. +1 −1 weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/media/data/TagW.java
  8. +12 −17 weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/service/AuditLog.java
  9. +28 −0 weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/DefaultView2d.java
  10. +9 −11 weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/MouseActions.java
  11. +7 −0 weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/PannerListener.java
  12. +2 −0 weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/ViewerToolBar.java
  13. +8 −0 weasis-dicom/weasis-dicom-codec/src/main/java/org/weasis/dicom/codec/DicomSeries.java
  14. +2 −16 weasis-dicom/weasis-dicom-codec/src/main/java/org/weasis/dicom/codec/internal/Activator.java
  15. +16 −12 weasis-dicom/weasis-dicom-viewer2d/src/main/java/org/weasis/dicom/viewer2d/EventManager.java
  16. +4 −0 weasis-dicom/weasis-dicom-viewer2d/src/main/java/org/weasis/dicom/viewer2d/View2d.java
  17. +2 −2 weasis-distributions/etc/config/config.properties
  18. +1 −1 weasis-launcher/conf/config.properties
  19. +2 −0 weasis-launcher/src/main/java/org/weasis/launcher/WeasisLauncher.java
@@ -20,6 +20,8 @@
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
+import org.weasis.core.api.service.AuditLog;
+
public abstract class ComboItemListener implements ListDataListener, ChangeListener, ActionState {
protected final ActionW action;
@@ -39,7 +41,9 @@ public ComboItemListener(ActionW action, Object[] objects) {
@Override
public void contentsChanged(ListDataEvent e) {
// if (model.equals(e.getSource())) {
- itemStateChanged(model.getSelectedItem());
+ Object val = model.getSelectedItem();
+ itemStateChanged(val);
+ AuditLog.LOGGER.info("action:{} val:{}", action.cmd(), val);
// }
}
@@ -26,6 +26,7 @@
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
+import org.weasis.core.api.service.AuditLog;
import org.weasis.core.api.util.FontTools;
public abstract class SliderChangeListener extends MouseActionAdapter implements ChangeListener, ActionState {
@@ -149,6 +150,8 @@ public void stateChanged(ChangeEvent evt) {
boolean ajusting = valueIsAdjusting ? true : !model.getValueIsAdjusting();
if (triggerAction && ajusting) {
stateChanged(model);
+ AuditLog.LOGGER.info("action:{} val:{} min:{} max:{}",
+ new Object[] { action.cmd(), model.getValue(), model.getMinimum(), model.getMaximum() });
}
for (int i = 0; i < sliders.size(); i++) {
updateSliderProoperties(sliders.get(i));
@@ -21,6 +21,8 @@
import javax.swing.JComponent;
import javax.swing.JToggleButton.ToggleButtonModel;
+import org.weasis.core.api.service.AuditLog;
+
public abstract class ToggleButtonListener implements ActionListener, ActionState {
protected final ArrayList<AbstractButton> itemList;
@@ -35,6 +37,7 @@ public ToggleButtonListener(ActionW action, boolean selected) {
model.addActionListener(this);
}
+ @Override
public void enableAction(boolean enabled) {
model.setEnabled(enabled);
}
@@ -44,13 +47,16 @@ public String toString() {
return action.getTitle();
}
+ @Override
public ActionW getActionW() {
return action;
}
+ @Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof ButtonModel) {
actionPerformed(model.isSelected());
+ AuditLog.LOGGER.info("action:{} val:{}", action.cmd(), model.isSelected());
}
};
@@ -65,6 +71,7 @@ public synchronized void setSelected(boolean selected) {
if (oldVal != selected) {
model.setSelected(selected);
actionPerformed(selected);
+ AuditLog.LOGGER.info("action:{} val:{}", action.cmd(), model.isSelected());
}
}
@@ -11,6 +11,10 @@
package org.weasis.core.api.internal;
import java.awt.image.renderable.RenderedImageFactory;
+import java.io.File;
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
import javax.media.jai.JAI;
import javax.media.jai.OperationDescriptorImpl;
@@ -26,9 +30,12 @@
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.weasis.core.api.gui.util.AbstractProperties;
import org.weasis.core.api.image.op.FormatBinaryDescriptor;
import org.weasis.core.api.image.op.ImageStatistics2Descriptor;
import org.weasis.core.api.image.op.ImageStatisticsDescriptor;
@@ -39,6 +46,7 @@
import org.weasis.core.api.image.op.ThresholdToBinDescriptor;
import org.weasis.core.api.image.util.ImageToolkit;
import org.weasis.core.api.media.data.Codec;
+import org.weasis.core.api.service.AuditLog;
import org.weasis.core.api.service.BundleTools;
import org.weasis.core.api.service.DataFileBackingStoreImpl;
import org.weasis.core.api.util.ProxyDetector;
@@ -91,6 +99,8 @@ public boolean errorOccurred(String message, Throwable thrown, Object where, boo
// Allows to connect through a proxy initialized by Java Webstart
ProxyDetector.setProxyFromJavaWebStart();
+
+ initLoggerAndAudit();
}
@Override
@@ -149,4 +159,41 @@ public static BundleContext getBundleContext() {
return bundleContext;
}
+ private void initLoggerAndAudit() throws IOException {
+ // Audit log for giving statistics about usage of Weasis
+ String loggerKey = "audit.log";
+ String[] loggerVal = new String[] { "org.weasis.core.api.service.AuditLog" };
+ // Activate audit log by adding an entry "audit.log=true" in Weasis.
+ String audit = bundleContext.getProperty(loggerKey);
+ if (audit != null && audit.equalsIgnoreCase("true")) {
+ String user = System.getProperty("weasis.user", System.getProperty("user.name", "local"));
+ AuditLog.createOrUpdateLogger(loggerKey, loggerVal, "DEBUG", AbstractProperties.WEASIS_PATH
+ + File.separator + "log" + File.separator + "audit-" + user + ".log",
+ "{0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* {5}", null, null);
+ AuditLog.LOGGER.info("Start audit log session");
+ } else {
+ ServiceReference configurationAdminReference =
+ bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
+ if (configurationAdminReference != null) {
+ ConfigurationAdmin confAdmin =
+ (ConfigurationAdmin) bundleContext.getService(configurationAdminReference);
+ if (confAdmin != null) {
+
+ Configuration logConfiguration = AuditLog.getLogConfiguration(confAdmin, loggerKey, loggerVal[0]);
+ if (logConfiguration == null) {
+ logConfiguration =
+ confAdmin.createFactoryConfiguration(
+ "org.apache.sling.commons.log.LogManager.factory.config", null);
+ Dictionary<String, Object> loggingProperties = new Hashtable<String, Object>();
+ loggingProperties.put("org.apache.sling.commons.log.level", "ERROR");
+ // loggingProperties.put("org.apache.sling.commons.log.file", "logs.log");
+ loggingProperties.put("org.apache.sling.commons.log.names", loggerVal);
+ // add this property to give us something unique to re-find this configuration
+ loggingProperties.put(loggerKey, loggerVal[0]);
+ logConfiguration.update(loggingProperties);
+ }
+ }
+ }
+ }
+ }
}
@@ -54,6 +54,8 @@
String getToolTips();
+ String getSeriesNumber();
+
boolean isOpen();
boolean isSelected();
@@ -430,4 +430,8 @@ public synchronized double getFileSize() {
return fileSize;
}
+ public String getSeriesNumber() {
+ Integer val = (Integer) getTagValue(TagW.SeriesNumber);
+ return val == null ? "" : val.toString();
+ }
}
@@ -66,7 +66,7 @@
public static final TagW ExplorerModel = new TagW(Messages.getString("TagElement.exp_model"), TagType.Object); //$NON-NLS-1$
public static final TagW MeasurementGraphics = new TagW(
Messages.getString("TagElement.measure_graph"), TagType.List);; //$NON-NLS-1$
- public static final TagW SplitSeriesNumber = new TagW(Messages.getString("TagElement.split_no"), TagType.Boolean); //$NON-NLS-1$
+ public static final TagW SplitSeriesNumber = new TagW(Messages.getString("TagElement.split_no"), TagType.Integer); //$NON-NLS-1$
public static final TagW SeriesSelected = new TagW(Messages.getString("TagElement.select"), TagType.Boolean); //$NON-NLS-1$
public static final TagW SeriesOpen = new TagW(Messages.getString("TagElement.open"), TagType.Boolean); //$NON-NLS-1$
public static final TagW ImageWidth = new TagW(Messages.getString("TagElement.img_w"), TagType.Integer); //$NON-NLS-1$
@@ -25,7 +25,7 @@
public static final String LOG_LOGGERS = "org.apache.sling.commons.log.names"; //$NON-NLS-1$
public enum LEVEL {
- DEBUG, INFO, WARN, ERROR, FATAL;
+ TRACE, DEBUG, INFO, WARN, ERROR;
public static LEVEL getLevel(String level) {
try {
@@ -36,13 +36,6 @@ public static LEVEL getLevel(String level) {
}
};
- // TODO activate audit log for the functionalities usage of Weasis
- // static {
- // AuditLog.createOrUpdateLogger("audit.log", new String[] { "org.weasis.core.api.service.AuditLog" }, "DEBUG",
- // AbstractProperties.WEASIS_PATH + File.separator + "log" + File.separator + "audit.log",
- // "{0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* {5}", null, null);
- // }
-
public static void createOrUpdateLogger(String loggerKey, String[] loggerVal, String level, String logFile,
String pattern, String nbFiles, String logSize) {
if (loggerKey != null && loggerVal != null && loggerVal.length > 0) {
@@ -56,8 +49,7 @@ public static void createOrUpdateLogger(String loggerKey, String[] loggerVal, St
if (confAdmin != null) {
try {
Dictionary<String, Object> loggingProperties;
- Configuration logConfiguration =
- getLogConfiguration(confAdmin, "(" + loggerKey + "=" + loggerVal[0] + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Configuration logConfiguration = getLogConfiguration(confAdmin, loggerKey, loggerVal[0]); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (logConfiguration == null) {
logConfiguration =
confAdmin.createFactoryConfiguration(
@@ -94,15 +86,18 @@ public static void createOrUpdateLogger(String loggerKey, String[] loggerVal, St
}
}
- public static Configuration getLogConfiguration(ConfigurationAdmin confAdmin, String filter) throws IOException {
+ public static Configuration getLogConfiguration(ConfigurationAdmin confAdmin, String key, String val)
+ throws IOException {
Configuration logConfiguration = null;
- try {
- Configuration[] configs = confAdmin.listConfigurations(filter);
- if (configs != null && configs.length > 0) {
- logConfiguration = configs[0];
+ if (key != null && val != null) {
+ try {
+ Configuration[] configs = confAdmin.listConfigurations("(" + key + "=" + val + ")");
+ if (configs != null && configs.length > 0) {
+ logConfiguration = configs[0];
+ }
+ } catch (InvalidSyntaxException e) {
+ // ignore this as we'll create what we need
}
- } catch (InvalidSyntaxException e) {
- // ignore this as we'll create what we need
}
return logConfiguration;
}
@@ -41,6 +41,7 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.RenderedImage;
+import java.awt.image.SampleModel;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
@@ -85,6 +86,7 @@
import org.weasis.core.api.media.data.Series;
import org.weasis.core.api.media.data.SeriesComparator;
import org.weasis.core.api.media.data.TagW;
+import org.weasis.core.api.service.AuditLog;
import org.weasis.core.api.util.FontTools;
import org.weasis.core.ui.Messages;
import org.weasis.core.ui.docking.UIManager;
@@ -398,6 +400,26 @@ protected void setImage(E img, boolean bestFit) {
actionsInView.put(ActionW.ZOOM.cmd(), -getBestFitViewScale());
}
imageLayer.setImage(img, (OperationsManager) actionsInView.get(ActionW.PREPROCESSING.cmd()));
+
+ if (AuditLog.LOGGER.isInfoEnabled()) {
+ PlanarImage image = img.getImage();
+ if (image != null) {
+ StringBuffer pixSize = new StringBuffer();
+ SampleModel sm = image.getSampleModel();
+ if (sm != null) {
+ int[] spsize = sm.getSampleSize();
+ if (spsize != null && spsize.length > 0) {
+ pixSize.append(spsize[0]);
+ for (int i = 1; i < spsize.length; i++) {
+ pixSize.append(',');
+ pixSize.append(spsize[i]);
+ }
+ }
+ }
+ AuditLog.LOGGER.info("open:image size:{},{} depth:{}",
+ new Object[] { image.getWidth(), image.getHeight(), pixSize.toString() });
+ }
+ }
}
}
@@ -532,6 +554,10 @@ public void setSelected(boolean selected) {
getLayerModel().setSelectedGraphics(null);
// Throws to the tool listener the current graphic selection.
getLayerModel().fireGraphicsSelectionChanged(imageLayer);
+
+ if (selected && series != null) {
+ AuditLog.LOGGER.info("select:series nb:{}", series.getSeriesNumber());
+ }
}
/** paint routine */
@@ -704,6 +730,8 @@ public void propertyChange(PropertyChangeEvent evt) {
series.getNearestImage(location, tileOffset,
(Filter<E>) actionsInView.get(ActionW.FILTERED_SERIES.cmd()),
getCurrentSortComparator());
+
+ AuditLog.LOGGER.info("synch:series nb:{}", series.getSeriesNumber());
}
} else {
if (value.getMedia() instanceof ImageElement) {
@@ -14,8 +14,8 @@
import org.osgi.service.prefs.Preferences;
import org.weasis.core.api.gui.util.ActionW;
+import org.weasis.core.api.service.AuditLog;
import org.weasis.core.api.service.BundlePreferences;
-import org.weasis.core.ui.Messages;
public class MouseActions {
@@ -36,8 +36,8 @@
private String middle = ActionW.PAN.cmd();
private String right = ActionW.CONTEXTMENU.cmd();
private String wheel = ActionW.SCROLL_SERIES.cmd();
- private int activeButtons =
- InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON3_DOWN_MASK | SCROLL_MASK;
+ private int activeButtons = InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON2_DOWN_MASK
+ | InputEvent.BUTTON3_DOWN_MASK | SCROLL_MASK;
public MouseActions(String left, String middle, String right, String wheel) {
super();
@@ -123,19 +123,17 @@ public void setAction(String type, String action) {
} else if (MouseActions.WHEEL.equals(type)) {
setWheel(action);
}
+ AuditLog.LOGGER.info("mouse:{} action:{}", type, action);
}
public static void loadPreferences(Preferences prefs, boolean defaultValue) {
if (prefs != null) {
Preferences p = prefs.node(MouseActions.PREFERENCE_NODE);
- p.put(P_MOUSE_LEFT, defaultValue ? ActionW.WINLEVEL.cmd() : p.get(P_MOUSE_LEFT, ActionW.WINLEVEL
- .cmd()));
- p.put(P_MOUSE_MIDDLE, defaultValue ? ActionW.PAN.cmd() : p.get(P_MOUSE_MIDDLE, ActionW.PAN
- .cmd()));
- p.put(P_MOUSE_RIGHT, defaultValue ? ActionW.CONTEXTMENU.cmd() : p.get(P_MOUSE_RIGHT,
- ActionW.CONTEXTMENU.cmd()));
- p.put(P_MOUSE_WHEEL, defaultValue ? ActionW.ZOOM.cmd() : p.get(P_MOUSE_WHEEL, ActionW.ZOOM
- .cmd()));
+ p.put(P_MOUSE_LEFT, defaultValue ? ActionW.WINLEVEL.cmd() : p.get(P_MOUSE_LEFT, ActionW.WINLEVEL.cmd()));
+ p.put(P_MOUSE_MIDDLE, defaultValue ? ActionW.PAN.cmd() : p.get(P_MOUSE_MIDDLE, ActionW.PAN.cmd()));
+ p.put(P_MOUSE_RIGHT,
+ defaultValue ? ActionW.CONTEXTMENU.cmd() : p.get(P_MOUSE_RIGHT, ActionW.CONTEXTMENU.cmd()));
+ p.put(P_MOUSE_WHEEL, defaultValue ? ActionW.ZOOM.cmd() : p.get(P_MOUSE_WHEEL, ActionW.ZOOM.cmd()));
}
}
Oops, something went wrong.

0 comments on commit cfbd982

Please sign in to comment.