Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2010-12-16 06:40:57 -0500
committerChristopher Frost2010-12-16 06:40:57 -0500
commit925b825d662b00468d050e2aabb21263b1c3843d (patch)
tree646141c31363f5187d71e3ac164290a2a82eca1f
parent892e3980a65bae61af53606aa61a8c474654f6e9 (diff)
downloadorg.eclipse.virgo.medic-925b825d662b00468d050e2aabb21263b1c3843d.tar.gz
org.eclipse.virgo.medic-925b825d662b00468d050e2aabb21263b1c3843d.tar.xz
org.eclipse.virgo.medic-925b825d662b00468d050e2aabb21263b1c3843d.zip
Missed files that had been deleted in the previous commit
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/dump/impl/logback/LogDumpContributor.java188
-rw-r--r--org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/dump/impl/logback/LogDumpContributorTests.java125
-rw-r--r--org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/dump/impl/logback/StubDump.java81
3 files changed, 0 insertions, 394 deletions
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/dump/impl/logback/LogDumpContributor.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/dump/impl/logback/LogDumpContributor.java
deleted file mode 100644
index ef89636..0000000
--- a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/dump/impl/logback/LogDumpContributor.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 VMware Inc.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * VMware Inc. - initial contribution
- *******************************************************************************/
-
-package org.eclipse.virgo.medic.dump.impl.logback;
-
-import java.io.PrintWriter;
-import java.util.Dictionary;
-import java.util.List;
-
-import org.eclipse.virgo.medic.dump.Dump;
-import org.eclipse.virgo.medic.dump.DumpContributionFailedException;
-import org.eclipse.virgo.medic.dump.DumpContributor;
-import org.eclipse.virgo.medic.impl.config.ConfigurationProvider;
-import org.eclipse.virgo.medic.log.impl.logback.LoggingListener;
-import org.slf4j.Marker;
-
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.PatternLayout;
-import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.core.helpers.CyclicBuffer;
-
-
-/**
- * A {@link DumpContributor} that stores {@link LoggingEvent LoggingEvents} in a {@link CyclicBuffer} and
- * when a dump is triggered, writes those entries (a small subset of all that it has seen) to the dump directory.
- * <p />
- *
- * <strong>Concurrent Semantics</strong><br />
- *
- * Not threadsafe
- *
- */
-public final class LogDumpContributor implements DumpContributor, LoggingListener {
-
- private static final String DEFAULT_LEVEL = Level.OFF.levelStr;
-
- private static final String DEFAULT_BUFFER_SIZE = "10000";
-
- private static final String DEFAULT_PATTERN = "%message%n";
-
- private static final String FILE_NAME = "log.log";
-
- private static final String NAME = "log";
-
- private final CyclicBuffer<LoggingEvent> buffer;
-
- private final ConfigurationProvider configurationProvider;
-
- private final Object monitor = new Object();
-
- @SuppressWarnings("unchecked")
- public LogDumpContributor(ConfigurationProvider configurationProvider) {
- this.configurationProvider = configurationProvider;
-
- Dictionary configDictionary = this.configurationProvider.getConfiguration();
- this.buffer = new CyclicBuffer<LoggingEvent>(getBufferSize(configDictionary));
- }
-
- public String getName() {
- return NAME;
- }
-
- public void contribute(Dump dump) throws DumpContributionFailedException {
- Level configuredLevel = getLevel();
- if (Level.OFF.levelInt > configuredLevel.levelInt) {
- PrintWriter writer = null;
- try {
- writer = new PrintWriter(dump.createFileWriter(FILE_NAME));
- List<LoggingEvent> loggingEvents = buffer.asList();
-
- PatternLayout layout = createLayout();
-
- for (LoggingEvent event : loggingEvents) {
- writer.print(layout.doLayout(event));
- }
- } finally {
- if (writer != null) {
- writer.close();
- }
- }
- }
- }
-
- private PatternLayout createLayout() {
- PatternLayout layout = new PatternLayout();
- layout.setPattern(getPattern(this.configurationProvider.getConfiguration()));
- layout.setContext(new LoggerContext());
- layout.start();
-
- return layout;
- }
-
- @SuppressWarnings("unchecked")
- private Level getLevel() {
- Dictionary configDictionary = this.configurationProvider.getConfiguration();
- String level = getLevel(configDictionary);
- return Level.valueOf(level);
- }
-
- @SuppressWarnings("unchecked")
- private int getBufferSize(Dictionary configuration) {
- String bufferSizeString = getStringFromConfiguration(configuration, ConfigurationProvider.KEY_LOG_DUMP_BUFFERSIZE, DEFAULT_BUFFER_SIZE);
- return Integer.parseInt(bufferSizeString);
- }
-
- @SuppressWarnings("unchecked")
- private String getLevel(Dictionary configuration) {
- return getStringFromConfiguration(configuration, ConfigurationProvider.KEY_LOG_DUMP_LEVEL, DEFAULT_LEVEL);
- }
-
- @SuppressWarnings("unchecked")
- private String getPattern(Dictionary configuration) {
- return getStringFromConfiguration(configuration, ConfigurationProvider.KEY_LOG_DUMP_PATTERN, DEFAULT_PATTERN);
- }
-
- @SuppressWarnings("unchecked")
- private String getStringFromConfiguration(Dictionary configuration, String key, String defaultValue) {
- String value = (String)configuration.get(key);
-
- if (value == null) {
- value = defaultValue;
- }
-
- return value;
- }
-
- public void onLogging(Logger logger, String fqcn, Marker marker,
- Level level, String message, Object param, Throwable throwable) {
-
- if (level.isGreaterOrEqual(getLevel())) {
- LoggingEvent event = new LoggingEvent(fqcn, logger, level, message, throwable, new Object[] {param});
- event.setMarker(marker);
- event.setThreadName(Thread.currentThread().getName());
-
- synchronized (this.monitor) {
- this.buffer.add(event);
- }
- }
- }
-
- public void onLogging(Logger logger, String fqcn, Marker marker,
- Level level, String message, Object param1, Object param2,
- Throwable throwable) {
-
- if (level.isGreaterOrEqual(getLevel())) {
- LoggingEvent event = new LoggingEvent(fqcn, logger, level, message, throwable, new Object[] {param1, param2});
- event.setMarker(marker);
- event.setThreadName(Thread.currentThread().getName());
-
- synchronized (this.monitor) {
- this.buffer.add(event);
- }
- }
- }
-
- public void onLogging(Logger logger, String fqcn, Marker marker,
- Level level, String message, Object[] params, Throwable throwable) {
-
- if (level.isGreaterOrEqual(getLevel())) {
- LoggingEvent event = new LoggingEvent(fqcn, logger, level, message, throwable, params);
- event.setMarker(marker);
- event.setThreadName(Thread.currentThread().getName());
-
- synchronized (this.monitor) {
- this.buffer.add(event);
- }
- }
- }
-
- /**
- *
- */
- public void clear() {
- synchronized (this.monitor) {
- this.buffer.clear();
- }
- }
-}
diff --git a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/dump/impl/logback/LogDumpContributorTests.java b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/dump/impl/logback/LogDumpContributorTests.java
deleted file mode 100644
index cbdb19b..0000000
--- a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/dump/impl/logback/LogDumpContributorTests.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 VMware Inc.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * VMware Inc. - initial contribution
- *******************************************************************************/
-
-package org.eclipse.virgo.medic.dump.impl.logback;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.eclipse.virgo.medic.dump.DumpContributionFailedException;
-import org.eclipse.virgo.medic.dump.impl.logback.LogDumpContributor;
-import org.eclipse.virgo.medic.impl.config.ConfigurationProvider;
-import org.junit.Test;
-import org.slf4j.LoggerFactory;
-
-import ch.qos.logback.classic.Level;
-
-import ch.qos.logback.classic.Logger;
-
-
-public class LogDumpContributorTests {
-
- @Test
- public void emptyLog() throws DumpContributionFailedException {
- LogDumpContributor contributor = getContributor();
- StubDump dump = getDump();
- contributor.contribute(dump);
-
- File logFile = dump.createFile("log.log");
- assertTrue(logFile.exists());
- assertEquals(0, logFile.length());
- }
-
- @Test
- public void nonEmptyLog() throws DumpContributionFailedException {
- LogDumpContributor contributor = getContributor();
- StubDump dump = getDump();
-
- driveLogging(contributor);
-
- contributor.contribute(dump);
-
- File logFile = dump.createFile("log.log");
- assertTrue(logFile.exists());
- assertEquals(1, countLines(logFile));
- }
-
- @Test
- public void wrappedLog() throws DumpContributionFailedException {
- LogDumpContributor contributor = getContributor();
- StubDump dump = getDump();
- driveLogging(contributor);
- driveLogging(contributor);
- driveLogging(contributor);
-
- contributor.contribute(dump);
-
- File logFile = dump.createFile("log.log");
- assertTrue(logFile.exists());
- assertEquals(2, countLines(logFile));
- }
-
- private LogDumpContributor getContributor() {
- LogDumpContributor contributor = new LogDumpContributor(new StaticConfigurationProvider());
- return contributor;
- }
-
- private StubDump getDump() {
- File dumpRoot = new File("target/serviceability/dump");
- dumpRoot.mkdirs();
- return new StubDump("testCause", new Date().getTime(), Collections.<String, Object> emptyMap(), new Throwable[0], dumpRoot);
- }
-
- private int countLines(File logFile) {
- BufferedReader reader = null;
- int count = 0;
- try {
- reader = new BufferedReader(new FileReader(logFile));
- while (reader.readLine() != null) {
- count++;
- }
- } catch (FileNotFoundException e) {
- } catch (IOException e) {
- } finally {
- try {
- if (reader != null) {
- reader.close();
- }
- } catch (IOException e) {
- }
- }
-
- return count;
- }
-
- private static final class StaticConfigurationProvider implements ConfigurationProvider {
- public Dictionary<String,String> getConfiguration() {
- Hashtable<String,String> configuration = new Hashtable<String,String>();
- configuration.put(ConfigurationProvider.KEY_LOG_DUMP_LEVEL, "debug");
- configuration.put(ConfigurationProvider.KEY_LOG_DUMP_BUFFERSIZE, "2");
- return configuration;
- }
- }
-
- private final void driveLogging(LogDumpContributor loggingContributor) {
- loggingContributor.onLogging((Logger)LoggerFactory.getLogger("test"), "com.foo.bar", null, Level.INFO, "test", null, null);
- }
-}
diff --git a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/dump/impl/logback/StubDump.java b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/dump/impl/logback/StubDump.java
deleted file mode 100644
index 6890508..0000000
--- a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/dump/impl/logback/StubDump.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 VMware Inc.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * VMware Inc. - initial contribution
- *******************************************************************************/
-
-package org.eclipse.virgo.medic.dump.impl.logback;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.Map;
-
-import org.eclipse.virgo.medic.dump.Dump;
-import org.eclipse.virgo.medic.dump.DumpContributionFailedException;
-
-
-public class StubDump implements Dump {
-
- private final File outputDirectory;
-
- private final String cause;
-
- private final Map<String, Object> context;
-
- private final Throwable[] throwables;
-
- private final long timestamp;
-
- public StubDump(String cause, long timestamp, Map<String, Object> context, Throwable[] throwables, File outputDirectory) {
- this.cause = cause;
- this.timestamp = timestamp;
- this.context = context;
- this.throwables = throwables;
- this.outputDirectory = outputDirectory;
- }
-
- public File createFile(String name) {
- return new File(outputDirectory, name);
- }
-
- public FileOutputStream createFileOutputStream(String name) throws DumpContributionFailedException {
- try {
- return new FileOutputStream(createFile(name));
- } catch (FileNotFoundException e) {
- throw new DumpContributionFailedException("Unable to open output stream '" + name + "'");
- }
- }
-
- public FileWriter createFileWriter(String name) throws DumpContributionFailedException {
- try {
- return new FileWriter(createFile(name));
- } catch (IOException e) {
- throw new DumpContributionFailedException("Unable to open file writer '" + name + "'");
- }
- }
-
- public String getCause() {
- return this.cause;
- }
-
- public Map<String, Object> getContext() {
- return this.context;
- }
-
- public Throwable[] getThrowables() {
- return this.throwables;
- }
-
- public long getTimestamp() {
- return this.timestamp;
- }
-
-}

Back to the top