summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Liebig2008-02-27 05:50:09 (EST)
committerStefan Liebig2008-02-27 05:50:09 (EST)
commit136d107ab64ea209dd88c57fa2d1ee8f20d145ac (patch)
tree1bed52ee312389a985a3d0e59772ab38034b4a87
parente3a8636c233d88036631cab67c6e0d9a5d1ed54a (diff)
downloadorg.eclipse.riena-136d107ab64ea209dd88c57fa2d1ee8f20d145ac.zip
org.eclipse.riena-136d107ab64ea209dd88c57fa2d1ee8f20d145ac.tar.gz
org.eclipse.riena-136d107ab64ea209dd88c57fa2d1ee8f20d145ac.tar.bz2
changed layout of logging, added configurable log level, optimized
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/logging/ConsoleLogger.java30
1 files changed, 22 insertions, 8 deletions
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/logging/ConsoleLogger.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/logging/ConsoleLogger.java
index 6b3dcbb..f9b9243 100644
--- a/org.eclipse.riena.core/src/org/eclipse/riena/core/logging/ConsoleLogger.java
+++ b/org.eclipse.riena.core/src/org/eclipse/riena/core/logging/ConsoleLogger.java
@@ -15,6 +15,7 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.Inet4Address;
import java.net.UnknownHostException;
+import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -29,11 +30,18 @@ import org.osgi.service.log.LogService;
*/
public class ConsoleLogger implements Logger {
+ /**
+ * The system property key to set the logging level for the console logger.
+ * Values should be integers corresponding to
+ * {@link org.osgi.service.log.LogService}.
+ */
+ public static final String CONSOLELOGGER_LEVEL_SYSTEM_PROPERTY = "org.eclipse.riena.consoleloggerlevel"; //$NON-NLS-1$
+
private String name;
- private String nameAndHost = null;
+ private static String nameAndHost;
+ private static DateFormat formatter;
- public ConsoleLogger(String name) {
- this.name = name;
+ static {
String user = System.getProperty("user.name", "?"); //$NON-NLS-1$ //$NON-NLS-2$
String host;
try {
@@ -44,6 +52,12 @@ public class ConsoleLogger implements Logger {
StringBuilder buffer = new StringBuilder();
buffer.append(user).append('@').append(host);
nameAndHost = buffer.toString();
+
+ formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z"); //$NON-NLS-1$
+ }
+
+ public ConsoleLogger(String name) {
+ this.name = name;
}
/*
@@ -57,7 +71,7 @@ public class ConsoleLogger implements Logger {
* @see org.eclipse.equinox.log.Logger#isLoggable(int)
*/
public boolean isLoggable(int level) {
- return true;
+ return level <= Integer.getInteger(CONSOLELOGGER_LEVEL_SYSTEM_PROPERTY, LogService.LOG_WARNING);
}
/*
@@ -109,10 +123,12 @@ public class ConsoleLogger implements Logger {
private void log(int level, Object context, ServiceReference sr, String message, Throwable throwable) {
StringBuilder bob = new StringBuilder();
- bob.append(SimpleDateFormat.getInstance().format(new Date()));
+ bob.append(formatter.format(new Date()));
bob.append(' ');
bob.append(nameAndHost);
bob.append(' ');
+ bob.append(getLevel(level));
+ bob.append(' ');
bob.append('[');
bob.append(Thread.currentThread().getName());
if (context != null) {
@@ -124,10 +140,8 @@ public class ConsoleLogger implements Logger {
bob.append(sr);
}
bob.append("] "); //$NON-NLS-1$
- bob.append(getLevel(level));
- bob.append(' ');
bob.append(name);
- bob.append(": "); //$NON-NLS-1$
+ bob.append(' ');
bob.append(message);
if (throwable != null) {
StringWriter stringWriter = new StringWriter();