summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Liebig2008-02-21 07:48:29 (EST)
committerStefan Liebig2008-02-21 07:48:29 (EST)
commit9e9c1f79c64425b9a92fd3f67e969d7d56d0ad8d (patch)
treed6adcdaa99f7b1cc9e7b9fed6cb464e4f337c2bc
parent96a68db73c716a1e026bd993fce8c135b235177c (diff)
downloadorg.eclipse.riena-9e9c1f79c64425b9a92fd3f67e969d7d56d0ad8d.zip
org.eclipse.riena-9e9c1f79c64425b9a92fd3f67e969d7d56d0ad8d.tar.gz
org.eclipse.riena-9e9c1f79c64425b9a92fd3f67e969d7d56d0ad8d.tar.bz2
avoid static fields + hide log filter
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/logging/AlwaysFilter.java22
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/logging/LogUtil.java49
2 files changed, 30 insertions, 41 deletions
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/logging/AlwaysFilter.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/logging/AlwaysFilter.java
deleted file mode 100644
index 801279e..0000000
--- a/org.eclipse.riena.core/src/org/eclipse/riena/core/logging/AlwaysFilter.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 compeople AG and others.
- * 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:
- * compeople AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.riena.core.logging;
-
-import org.eclipse.equinox.log.LogFilter;
-import org.osgi.framework.Bundle;
-
-public class AlwaysFilter implements LogFilter {
-
- public boolean isLoggable(Bundle b, String loggerName, int logLevel) {
- return true;
- }
-
-} \ No newline at end of file
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/logging/LogUtil.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/logging/LogUtil.java
index fa54643..1b5f3d6 100644
--- a/org.eclipse.riena.core/src/org/eclipse/riena/core/logging/LogUtil.java
+++ b/org.eclipse.riena.core/src/org/eclipse/riena/core/logging/LogUtil.java
@@ -12,8 +12,10 @@ package org.eclipse.riena.core.logging;
import org.eclipse.equinox.log.ExtendedLogReaderService;
import org.eclipse.equinox.log.ExtendedLogService;
+import org.eclipse.equinox.log.LogFilter;
import org.eclipse.equinox.log.Logger;
import org.eclipse.riena.core.service.ServiceId;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
/**
@@ -21,26 +23,26 @@ import org.osgi.framework.BundleContext;
*/
public class LogUtil {
- private static ExtendedLogService logService;
+ private ExtendedLogService logService;
private ExtendedLogReaderService logReaderService;
- private static boolean initialized = false;
+ private boolean initialized = false;
private BundleContext context;
public LogUtil(BundleContext context) {
this.context = context;
}
+ /**
+ * Get the logger for the specified category.<br>
+ * <b>Note:</b> Use the log levels defined in
+ * {@link org.osgi.service.log.LogService}
+ *
+ * @param name
+ * @return
+ */
public Logger getLogger(String name) {
- if (!initialized) {
- init();
- initialized = true;
- }
- if (logService != null) {
- return logService.getLogger(name);
- } else {
- return new NullLogger();
- }
-
+ init();
+ return logService == null ? new NullLogger() : logService.getLogger(name);
}
/**
@@ -48,8 +50,8 @@ public class LogUtil {
*
* @param logService
*/
- public void bind(ExtendedLogService logServiceParm) {
- logService = logServiceParm;
+ public void bind(ExtendedLogService logService) {
+ this.logService = logService;
}
/**
@@ -57,8 +59,8 @@ public class LogUtil {
*
* @param logService
*/
- public void unbind(ExtendedLogService logServiceParm) {
- logService = null;
+ public void unbind(ExtendedLogService logService) {
+ this.logService = null;
}
/**
@@ -69,8 +71,8 @@ public class LogUtil {
public void bind(ExtendedLogReaderService logReaderService) {
this.logReaderService = logReaderService;
// TODO remove SysoLogListener if we have Log4jLogListener
- this.logReaderService.addLogListener(new SysoLogListener(), new AlwaysFilter());
- this.logReaderService.addLogListener(new Log4jLogListener(), new AlwaysFilter());
+ this.logReaderService.addLogListener(new SysoLogListener(), new LogAlwaysFilter());
+ this.logReaderService.addLogListener(new Log4jLogListener(), new LogAlwaysFilter());
}
/**
@@ -85,8 +87,17 @@ public class LogUtil {
/**
* initialize LogUtil
*/
- public void init() {
+ private synchronized void init() {
+ if (initialized)
+ return;
new ServiceId(ExtendedLogService.class.getName()).useRanking().injectInto(this).andStart(context);
new ServiceId(ExtendedLogReaderService.class.getName()).useRanking().injectInto(this).andStart(context);
+ initialized = true;
+ }
+
+ private static final class LogAlwaysFilter implements LogFilter {
+ public boolean isLoggable(Bundle b, String loggerName, int logLevel) {
+ return true;
+ }
}
}