You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by st...@apache.org on 2015/01/03 19:07:45 UTC
[4/9] incubator-tamaya git commit: remove logger abstraction
remove logger abstraction
this should not be part of our project but part of the container integration if any.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/4af87fcc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/4af87fcc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/4af87fcc
Branch: refs/heads/master
Commit: 4af87fcce3ef77679e87d3cd024a937516922b69
Parents: a6c0800
Author: Mark Struberg <st...@apache.org>
Authored: Sat Jan 3 18:11:05 2015 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Sat Jan 3 18:11:05 2015 +0100
----------------------------------------------------------------------
.../logging/AbstractDelegatingLogger.java | 415 -------------------
.../core/internal/logging/Log4j2Logger.java | 97 -----
.../core/internal/logging/Log4jLogger.java | 200 ---------
.../core/internal/logging/Slf4jLogger.java | 181 --------
4 files changed, 893 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4af87fcc/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java b/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
deleted file mode 100644
index 30c2d2e..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.logging;
-
-import java.text.MessageFormat;
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.logging.Filter;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
-
-/**
- * java.util.logging.Logger implementation delegating to another framework.
- * All methods can be used except:
- * setLevel
- * addHandler / getHandlers
- * setParent / getParent
- * setUseParentHandlers / getUseParentHandlers
- *
- * @author gnodet
- */
-public abstract class AbstractDelegatingLogger extends Logger {
-
- protected AbstractDelegatingLogger(final String name, final String resourceBundleName) {
- super(name, resourceBundleName);
- }
-
- public void log(final LogRecord record) {
- if (isLoggable(record.getLevel())) {
- doLog(record);
- }
- }
-
- public void log(final Level level, final String msg) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- doLog(lr);
- }
- }
-
- public void log(final Level level, final String msg, final Object param1) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- final Object[] params = {param1};
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- public void log(final Level level, final String msg, final Object[] params) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- public void log(final Level level, final String msg, final Throwable thrown) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setThrown(thrown);
- doLog(lr);
- }
- }
-
- public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- doLog(lr);
- }
- }
-
- public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg, final Object param1) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- final Object[] params = {param1};
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg, final Object[] params) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg, final Throwable thrown) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setThrown(thrown);
- doLog(lr);
- }
- }
-
- public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName, final String msg) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- doLog(lr, bundleName);
- }
- }
-
- public void logrb(final Level level, final String sourceClass, final String sourceMethod,
- final String bundleName, final String msg, final Object param1) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- final Object[] params = {param1};
- lr.setParameters(params);
- doLog(lr, bundleName);
- }
- }
-
- public void logrb(final Level level, final String sourceClass, final String sourceMethod,
- final String bundleName, final String msg, final Object[] params) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setParameters(params);
- doLog(lr, bundleName);
- }
- }
-
- public void logrb(final Level level, final String sourceClass, final String sourceMethod,
- final String bundleName, final String msg, final Throwable thrown) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setThrown(thrown);
- doLog(lr, bundleName);
- }
- }
-
- public void entering(final String sourceClass, final String sourceMethod) {
- if (isLoggable(Level.FINER)) {
- logp(Level.FINER, sourceClass, sourceMethod, "ENTRY");
- }
- }
-
- public void entering(final String sourceClass, final String sourceMethod, final Object param1) {
- if (isLoggable(Level.FINER)) {
- final Object[] params = {param1};
- logp(Level.FINER, sourceClass, sourceMethod, "ENTRY {0}", params);
- }
- }
-
- public void entering(final String sourceClass, final String sourceMethod, final Object[] params) {
- if (isLoggable(Level.FINER)) {
- final String msg = "ENTRY";
- if (params == null) {
- logp(Level.FINER, sourceClass, sourceMethod, msg);
- return;
- }
- final StringBuilder builder = new StringBuilder(msg);
- for (int i = 0; i < params.length; i++) {
- builder.append(" {");
- builder.append(Integer.toString(i));
- builder.append("}");
- }
- logp(Level.FINER, sourceClass, sourceMethod, builder.toString(), params);
- }
- }
-
- public void exiting(final String sourceClass, final String sourceMethod) {
- if (isLoggable(Level.FINER)) {
- logp(Level.FINER, sourceClass, sourceMethod, "RETURN");
- }
- }
-
- public void exiting(final String sourceClass, final String sourceMethod, final Object result) {
- if (isLoggable(Level.FINER)) {
- final Object[] params = {result};
- logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", params);
- }
- }
-
- public void throwing(final String sourceClass, final String sourceMethod, final Throwable thrown) {
- if (isLoggable(Level.FINER)) {
- final LogRecord lr = new LogRecord(Level.FINER, "THROW");
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setThrown(thrown);
- doLog(lr);
- }
- }
-
- public void severe(final String msg) {
- if (isLoggable(Level.SEVERE)) {
- final LogRecord lr = new LogRecord(Level.SEVERE, msg);
- doLog(lr);
- }
- }
-
- public void warning(final String msg) {
- if (isLoggable(Level.WARNING)) {
- final LogRecord lr = new LogRecord(Level.WARNING, msg);
- doLog(lr);
- }
- }
-
- public void info(final String msg) {
- if (isLoggable(Level.INFO)) {
- final LogRecord lr = new LogRecord(Level.INFO, msg);
- doLog(lr);
- }
- }
-
- public void config(final String msg) {
- if (isLoggable(Level.CONFIG)) {
- final LogRecord lr = new LogRecord(Level.CONFIG, msg);
- doLog(lr);
- }
- }
-
- public void fine(final String msg) {
- if (isLoggable(Level.FINE)) {
- final LogRecord lr = new LogRecord(Level.FINE, msg);
- doLog(lr);
- }
- }
-
- public void finer(final String msg) {
- if (isLoggable(Level.FINER)) {
- final LogRecord lr = new LogRecord(Level.FINER, msg);
- doLog(lr);
- }
- }
-
- public void finest(final String msg) {
- if (isLoggable(Level.FINEST)) {
- final LogRecord lr = new LogRecord(Level.FINEST, msg);
- doLog(lr);
- }
- }
-
- public void setLevel(final Level newLevel) throws SecurityException {
- throw new UnsupportedOperationException();
- }
-
- public abstract Level getLevel();
-
- public boolean isLoggable(final Level level) {
- final Level l = getLevel();
- return level.intValue() >= l.intValue() && l != Level.OFF;
- }
-
- protected boolean supportsHandlers() {
- return false;
- }
-
- public synchronized void addHandler(final Handler handler) throws SecurityException {
- if (supportsHandlers()) {
- super.addHandler(handler);
- return;
- }
- throw new UnsupportedOperationException();
- }
-
- public synchronized void removeHandler(final Handler handler) throws SecurityException {
- if (supportsHandlers()) {
- super.removeHandler(handler);
- return;
- }
- throw new UnsupportedOperationException();
- }
-
- public synchronized Handler[] getHandlers() {
- if (supportsHandlers()) {
- return super.getHandlers();
- }
- throw new UnsupportedOperationException();
- }
-
- public synchronized void setUseParentHandlers(final boolean useParentHandlers) {
- if (supportsHandlers()) {
- super.setUseParentHandlers(useParentHandlers);
- return;
- }
- throw new UnsupportedOperationException();
- }
-
- public synchronized boolean getUseParentHandlers() {
- if (supportsHandlers()) {
- return super.getUseParentHandlers();
- }
- throw new UnsupportedOperationException();
- }
-
- public Logger getParent() {
- return null;
- }
-
- public void setParent(final Logger parent) {
- throw new UnsupportedOperationException();
- }
-
- protected void doLog(final LogRecord lr) {
- lr.setLoggerName(getName());
- final String rbname = getResourceBundleName();
- if (rbname != null) {
- lr.setResourceBundleName(rbname);
- lr.setResourceBundle(getResourceBundle());
- }
- internalLog(lr);
- }
-
- protected void doLog(final LogRecord lr, final String rbname) {
- lr.setLoggerName(getName());
- if (rbname != null) {
- lr.setResourceBundleName(rbname);
- lr.setResourceBundle(loadResourceBundle(rbname));
- }
- internalLog(lr);
- }
-
- protected void internalLog(final LogRecord record) {
- final Filter filter = getFilter();
- if (filter != null && !filter.isLoggable(record)) {
- return;
- }
- final String msg = formatMessage(record);
- internalLogFormatted(msg, record);
- }
-
- protected abstract void internalLogFormatted(String msg, LogRecord record);
-
- protected String formatMessage(final LogRecord record) {
- String format = record.getMessage();
- final ResourceBundle catalog = record.getResourceBundle();
- if (catalog != null) {
- try {
- format = catalog.getString(record.getMessage());
- } catch (final MissingResourceException ex) {
- format = record.getMessage();
- }
- }
- try {
- final Object[] parameters = record.getParameters();
- if (parameters == null || parameters.length == 0) {
- return format;
- }
- if (format.contains("{0") || format.contains("{1")
- || format.contains("{2") || format.contains("{3")) {
- return MessageFormat.format(format, parameters);
- }
- return format;
- } catch (final Exception ex) {
- return format;
- }
- }
-
- /**
- * Load the specified resource bundle
- *
- * @param resourceBundleName the name current the resource bundle to load, cannot be null
- * @return the loaded resource bundle.
- * @throws MissingResourceException If the specified resource bundle can not be loaded.
- */
- static ResourceBundle loadResourceBundle(final String resourceBundleName) {
- // try context class loader to load the resource
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (null != cl) {
- try {
- return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
- } catch (final MissingResourceException e) {
- // Failed to load using context classloader, ignore
- }
- }
- // try system class loader to load the resource
- cl = ClassLoader.getSystemClassLoader();
- if (null != cl) {
- try {
- return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
- } catch (final MissingResourceException e) {
- // Failed to load using system classloader, ignore
- }
- }
- return null;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4af87fcc/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java b/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java
deleted file mode 100644
index 35ae4ab..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.logging;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-public class Log4j2Logger extends AbstractDelegatingLogger {
- private static final Map<Level, org.apache.logging.log4j.Level> TO_LOG4J = new HashMap<>();
-
- private final Logger log;
-
- static {
- //older versions current log4j don't have TRACE, use debug
-// org.apache.logging.log4j.Level t = org.apache.logging.log4j.Level.DEBUG;
-
- TO_LOG4J.put(Level.ALL, org.apache.logging.log4j.Level.ALL);
- TO_LOG4J.put(Level.SEVERE, org.apache.logging.log4j.Level.ERROR);
- TO_LOG4J.put(Level.WARNING, org.apache.logging.log4j.Level.WARN);
- TO_LOG4J.put(Level.INFO, org.apache.logging.log4j.Level.INFO);
- TO_LOG4J.put(Level.CONFIG, org.apache.logging.log4j.Level.DEBUG);
- TO_LOG4J.put(Level.FINE, org.apache.logging.log4j.Level.DEBUG);
- TO_LOG4J.put(Level.FINER, org.apache.logging.log4j.Level.TRACE);
- TO_LOG4J.put(Level.FINEST, org.apache.logging.log4j.Level.TRACE);
- TO_LOG4J.put(Level.OFF, org.apache.logging.log4j.Level.OFF);
- }
-
- public Log4j2Logger(final String name, final String resourceBundleName) {
- super(name, resourceBundleName);
- log = LogManager.getLogger(name);
- }
-
- public Level getLevel() {
- final org.apache.logging.log4j.Level l = log.getLevel();
- if (l != null) {
- return fromL4J(l);
- }
- return null;
- }
-
- protected void internalLogFormatted(final String msg, final LogRecord record) {
- log.log(TO_LOG4J.get(record.getLevel()), msg, record.getThrown());
- }
-
-
- private Level fromL4J(final org.apache.logging.log4j.Level l) {
- Level l2 = null;
- switch (l.getStandardLevel()) {
- case ALL:
- l2 = Level.ALL;
- break;
- case FATAL:
- l2 = Level.SEVERE;
- break;
- case ERROR:
- l2 = Level.SEVERE;
- break;
- case WARN:
- l2 = Level.WARNING;
- break;
- case INFO:
- l2 = Level.INFO;
- break;
- case DEBUG:
- l2 = Level.FINE;
- break;
- case OFF:
- l2 = Level.OFF;
- break;
- case TRACE:
- l2 = Level.FINEST;
- break;
- default:
- l2 = Level.FINE;
- }
- return l2;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4af87fcc/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java b/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java
deleted file mode 100644
index 224378c..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.logging;
-
-import org.apache.log4j.Appender;
-import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.apache.log4j.Priority;
-import org.apache.log4j.spi.LoggingEvent;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-/**
- * java.util.logging.Logger implementation delegating to Log4j.
- * All methods can be used except:
- * setLevel
- * addHandler / getHandlers
- * setParent / getParent
- * setUseParentHandlers / getUseParentHandlers
- *
- * @author gnodet
- */
-public class Log4jLogger extends AbstractDelegatingLogger {
- private static final Map<Level, org.apache.log4j.Level> TO_LOG4J = new HashMap<>();
- private static final org.apache.log4j.Level TRACE;
-
- private final Logger log;
-
- static {
- //older versions current log4j don't have TRACE, use debug
- org.apache.log4j.Level t = org.apache.log4j.Level.DEBUG;
- try {
- final Field f = org.apache.log4j.Level.class.getField("TRACE");
- t = (org.apache.log4j.Level) f.get(null);
- } catch (final Throwable ex) {
- //ignore, assume old version current log4j
- }
- TRACE = t;
-
- TO_LOG4J.put(Level.ALL, org.apache.log4j.Level.ALL);
- TO_LOG4J.put(Level.SEVERE, org.apache.log4j.Level.ERROR);
- TO_LOG4J.put(Level.WARNING, org.apache.log4j.Level.WARN);
- TO_LOG4J.put(Level.INFO, org.apache.log4j.Level.INFO);
- TO_LOG4J.put(Level.CONFIG, org.apache.log4j.Level.DEBUG);
- TO_LOG4J.put(Level.FINE, org.apache.log4j.Level.DEBUG);
- TO_LOG4J.put(Level.FINER, TRACE);
- TO_LOG4J.put(Level.FINEST, TRACE);
- TO_LOG4J.put(Level.OFF, org.apache.log4j.Level.OFF);
- }
-
- public Log4jLogger(final String name, final String resourceBundleName) {
- super(name, resourceBundleName);
- log = LogManager.getLogger(name);
- }
-
- public Level getLevel() {
- final org.apache.log4j.Level l = log.getEffectiveLevel();
- if (l != null) {
- return fromL4J(l);
- }
- return null;
- }
-
- public void setLevel(final Level newLevel) throws SecurityException {
- log.setLevel(TO_LOG4J.get(newLevel));
- }
-
- public synchronized void addHandler(final Handler handler) throws SecurityException {
- log.addAppender(new HandlerWrapper(handler));
- }
-
- public synchronized void removeHandler(final Handler handler) throws SecurityException {
- log.removeAppender("HandlerWrapper-" + handler.hashCode());
- }
-
- public synchronized Handler[] getHandlers() {
- final List<Handler> ret = new ArrayList<>();
- final Enumeration<?> en = log.getAllAppenders();
- while (en.hasMoreElements()) {
- final Appender ap = (Appender) en.nextElement();
- if (ap instanceof HandlerWrapper) {
- ret.add(((HandlerWrapper) ap).getHandler());
- }
- }
- return ret.toArray(new Handler[ret.size()]);
- }
-
- protected void internalLogFormatted(final String msg, final LogRecord record) {
- log.log(AbstractDelegatingLogger.class.getName(),
- TO_LOG4J.get(record.getLevel()),
- msg,
- record.getThrown());
- }
-
-
- private Level fromL4J(final org.apache.log4j.Level l) {
- Level l2 = null;
- switch (l.toInt()) {
- case org.apache.log4j.Level.ALL_INT:
- l2 = Level.ALL;
- break;
- case org.apache.log4j.Level.FATAL_INT:
- l2 = Level.SEVERE;
- break;
- case org.apache.log4j.Level.ERROR_INT:
- l2 = Level.SEVERE;
- break;
- case org.apache.log4j.Level.WARN_INT:
- l2 = Level.WARNING;
- break;
- case org.apache.log4j.Level.INFO_INT:
- l2 = Level.INFO;
- break;
- case org.apache.log4j.Level.DEBUG_INT:
- l2 = Level.FINE;
- break;
- case org.apache.log4j.Level.OFF_INT:
- l2 = Level.OFF;
- break;
- default:
- if (l.toInt() == TRACE.toInt()) {
- l2 = Level.FINEST;
- }
- }
- return l2;
- }
-
-
- private class HandlerWrapper extends AppenderSkeleton {
- Handler handler;
-
- public HandlerWrapper(final Handler h) {
- handler = h;
- name = "HandlerWrapper-" + h.hashCode();
- }
-
- public Handler getHandler() {
- return handler;
- }
-
- @Override
- protected void append(final LoggingEvent event) {
- final LogRecord lr = new LogRecord(fromL4J(event.getLevel()),
- event.getMessage().toString());
- lr.setLoggerName(event.getLoggerName());
- if (event.getThrowableInformation() != null) {
- lr.setThrown(event.getThrowableInformation().getThrowable());
- }
- final String rbname = getResourceBundleName();
- if (rbname != null) {
- lr.setResourceBundleName(rbname);
- lr.setResourceBundle(getResourceBundle());
- }
- handler.publish(lr);
- }
-
- public void close() {
- handler.close();
- closed = true;
- }
-
- public boolean requiresLayout() {
- return false;
- }
-
- @Override
- public Priority getThreshold() {
- return TO_LOG4J.get(handler.getLevel());
- }
-
- @Override
- public boolean isAsSevereAsThreshold(final Priority priority) {
- final Priority p = getThreshold();
- return p == null || priority.isGreaterOrEqual(p);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4af87fcc/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java b/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
deleted file mode 100644
index a580128..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.logging;
-
-import org.slf4j.spi.LocationAwareLogger;
-
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-/**
- * <p>
- * java.util.logging.Logger implementation delegating to SLF4J.
- * </p>
- * <p>
- * Methods {@link java.util.logging.Logger#setParent(Logger)}, {@link java.util.logging.Logger#getParent()},
- * {@link java.util.logging.Logger#setUseParentHandlers(boolean)} and
- * {@link java.util.logging.Logger#getUseParentHandlers()} are not overrriden.
- * </p>
- * <p>
- * Level annotation inspired by {@link org.slf4j.bridge.SLF4JBridgeHandler}:
- * </p>
- * <p/>
- * <pre>
- * FINEST -> TRACE
- * FINER -> DEBUG
- * FINE -> DEBUG
- * CONFIG -> DEBUG
- * INFO -> INFO
- * WARN ING -> WARN
- * SEVER -> ERROR
- * </pre>
- */
-public class Slf4jLogger extends AbstractDelegatingLogger {
-
- private static final String FQCN = AbstractDelegatingLogger.class.getName();
-
- private final org.slf4j.Logger logger;
- private LocationAwareLogger locationAwareLogger;
-
-
- public Slf4jLogger(final String name, final String resourceBundleName) {
- super(name, resourceBundleName);
- logger = org.slf4j.LoggerFactory.getLogger(name);
- if (logger instanceof LocationAwareLogger) {
- locationAwareLogger = (LocationAwareLogger) logger;
- }
- }
-
- @Override
- protected boolean supportsHandlers() {
- return true;
- }
-
- @Override
- public Level getLevel() {
- final Level level;
- // Verify fromMap the wider (trace) to the narrower (error)
- if (logger.isTraceEnabled()) {
- level = Level.FINEST;
- } else if (logger.isDebugEnabled()) {
- // map to the lowest between FINER, FINE and CONFIG
- level = Level.FINER;
- } else if (logger.isInfoEnabled()) {
- level = Level.INFO;
- } else if (logger.isWarnEnabled()) {
- level = Level.WARNING;
- } else if (logger.isErrorEnabled()) {
- level = Level.SEVERE;
- } else {
- level = Level.OFF;
- }
- return level;
- }
-
- @Override
- public boolean isLoggable(final Level level) {
- final int i = level.intValue();
- if (i == Level.OFF.intValue()) {
- return false;
- } else if (i >= Level.SEVERE.intValue()) {
- return logger.isErrorEnabled();
- } else if (i >= Level.WARNING.intValue()) {
- return logger.isWarnEnabled();
- } else if (i >= Level.INFO.intValue()) {
- return logger.isInfoEnabled();
- } else if (i >= Level.FINER.intValue()) {
- return logger.isDebugEnabled();
- }
- return logger.isTraceEnabled();
- }
-
-
- @Override
- protected void internalLogFormatted(final String msg, final LogRecord record) {
-
- final Level level = record.getLevel();
- final Throwable t = record.getThrown();
-
- final Handler[] targets = getHandlers();
- if (targets != null) {
- for (final Handler h : targets) {
- h.publish(record);
- }
- }
- if (!getUseParentHandlers()) {
- return;
- }
-
- /*
- * As we can not use a "switch ... case" block but only a "if ... else if ..." block, the order current the
- * comparisons is important. We first try log level FINE then INFO, WARN, FINER, etc
- */
- if (Level.FINE.equals(level)) {
- if (locationAwareLogger == null) {
- logger.debug(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
- }
- } else if (Level.INFO.equals(level)) {
- if (locationAwareLogger == null) {
- logger.info(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, t);
- }
- } else if (Level.WARNING.equals(level)) {
- if (locationAwareLogger == null) {
- logger.warn(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, t);
- }
- } else if (Level.FINER.equals(level)) {
- if (locationAwareLogger == null) {
- logger.trace(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
- }
- } else if (Level.FINEST.equals(level)) {
- if (locationAwareLogger == null) {
- logger.trace(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, t);
- }
- } else if (Level.ALL.equals(level)) {
- // should never occur, all is used to configure java.util.logging
- // but not accessible by the API Logger.xxx() API
- if (locationAwareLogger == null) {
- logger.error(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
- }
- } else if (Level.SEVERE.equals(level)) {
- if (locationAwareLogger == null) {
- logger.error(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
- }
- } else if (Level.CONFIG.equals(level)) {
- if (locationAwareLogger == null) {
- logger.debug(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
- }
- }
- // don't log if Level.OFF
- }
-}