diff --git a/core/.classpath b/core/.classpath index 440a891bb..dd7a75cf8 100644 --- a/core/.classpath +++ b/core/.classpath @@ -32,7 +32,7 @@ - + diff --git a/core/build.xml b/core/build.xml index 9fd561139..04820e3a4 100644 --- a/core/build.xml +++ b/core/build.xml @@ -84,7 +84,7 @@ - + @@ -102,7 +102,10 @@ - + + + + diff --git a/core/src/logback.xml b/core/src/logback.xml index 2d46da464..930599f30 100644 --- a/core/src/logback.xml +++ b/core/src/logback.xml @@ -1,18 +1,8 @@ - - - - - - - - - - - + + - \ No newline at end of file diff --git a/core/src/net/sf/openrocket/logging/LoggingSystemSetup.java b/core/src/net/sf/openrocket/logging/LoggingSystemSetup.java index 68edcfdce..ffdcc63d7 100644 --- a/core/src/net/sf/openrocket/logging/LoggingSystemSetup.java +++ b/core/src/net/sf/openrocket/logging/LoggingSystemSetup.java @@ -3,6 +3,10 @@ package net.sf.openrocket.logging; import org.slf4j.LoggerFactory; import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.encoder.PatternLayoutEncoder; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.ConsoleAppender; public class LoggingSystemSetup { @@ -12,6 +16,25 @@ public class LoggingSystemSetup { // there is an appender named "buffer" and that appender // is the LogbackBufferLoggerAdapter. + /** + * Add a Console Appender. We do this programmatically so the application does not need + * to include additional jars required for the logback syntax to function. + */ + public static void addConsoleAppender() { + Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); + LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); + ConsoleAppender appender = new ConsoleAppender(); + appender.setName("console"); + appender.setContext(context); + PatternLayoutEncoder layout = new PatternLayoutEncoder(); + layout.setContext(context); + layout.setPattern("%-8relative %-5marker %-5level [%thread] %logger{2} - %message%n%caller{2, BAD}"); + layout.start(); + appender.setEncoder(layout); + appender.start(); + logger.addAppender(appender); + } + /** * Get the logger to be used in logging. * diff --git a/core/src/net/sf/openrocket/startup/GuiceStartup.java b/core/src/net/sf/openrocket/startup/GuiceStartup.java index 1aa6ffb42..8b09d66aa 100644 --- a/core/src/net/sf/openrocket/startup/GuiceStartup.java +++ b/core/src/net/sf/openrocket/startup/GuiceStartup.java @@ -10,6 +10,7 @@ import net.sf.openrocket.l10n.L10N; import net.sf.openrocket.l10n.ResourceBundleTranslator; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.logging.LogLevel; +import net.sf.openrocket.logging.LoggingSystemSetup; import net.sf.openrocket.logging.PrintStreamLogger; import net.sf.openrocket.logging.PrintStreamToSLF4J; import net.sf.openrocket.plugin.PluginModule; @@ -89,7 +90,9 @@ public class GuiceStartup { * Initializes the logging system. */ public static void initializeLogging() { - + if (System.getProperty("openrocket.debug") != null) { + LoggingSystemSetup.addConsoleAppender(); + } //Replace System.err with a PrintStream that logs lines to DEBUG, or VBOSE if they are indented. //If debug info is not being output to the console then the data is both logged and written to //stderr.