Removing the unused logger integration (for Hibernate <3.3)

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15465 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Adam Warski 2008-10-31 12:26:41 +00:00
parent a94515206d
commit f9913f9e5e
3 changed files with 3 additions and 183 deletions

View File

@ -40,8 +40,6 @@ import org.hibernate.envers.entities.mapper.ExtendedPropertyMapper;
import org.hibernate.envers.entities.mapper.MultiPropertyMapper;
import org.hibernate.envers.entities.mapper.SubclassPropertyMapper;
import org.hibernate.envers.tools.StringTools;
import org.hibernate.envers.tools.log.YLog;
import org.hibernate.envers.tools.log.YLogManager;
import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
@ -54,6 +52,8 @@ import org.hibernate.type.CollectionType;
import org.hibernate.type.ManyToOneType;
import org.hibernate.type.OneToOneType;
import org.hibernate.type.Type;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
/**
* @author Adam Warski (adam at warski dot org)
@ -74,7 +74,7 @@ public final class AuditMetadataGenerator {
// Map entity name -> (join descriptor -> element describing the "versioned" join)
private final Map<String, Map<Join, Element>> entitiesJoins;
private YLog log = YLogManager.getLogManager().getLog(AuditMetadataGenerator.class);
private Logger log = LoggerFactory.getLogger(AuditMetadataGenerator.class);
public AuditMetadataGenerator(Configuration cfg, GlobalConfiguration globalCfg,
AuditEntitiesConfiguration verEntCfg,

View File

@ -1,92 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.tools.log;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.hibernate.envers.exception.AuditException;
/**
* A simple logger facade which delegates through reflection to a logging delegate.
* @author Adam Warski (adam at warski dot org)
*/
public class YLog {
private final Object delegate;
private final Method errorMethod;
private final Method warnMethod;
private final Method infoMethod;
public YLog(Object delegate, Class<?> argClass) {
this.delegate = delegate;
try {
errorMethod = delegate.getClass().getMethod("error", argClass);
} catch (NoSuchMethodException e) {
throw new AuditException(e);
}
try {
warnMethod = delegate.getClass().getMethod("warn", argClass);
} catch (NoSuchMethodException e) {
throw new AuditException(e);
}
try {
infoMethod = delegate.getClass().getMethod("info", argClass);
} catch (NoSuchMethodException e) {
throw new AuditException(e);
}
}
public void error(String message) {
try {
errorMethod.invoke(delegate, message);
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
public void warn(String message) {
try {
warnMethod.invoke(delegate, message);
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
public void info(String message) {
try {
infoMethod.invoke(delegate, message);
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
}

View File

@ -1,88 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.tools.log;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.hibernate.envers.exception.AuditException;
/**
* A class for creating logging facades either to loggers obtained from
* <code>org.apache.commons.logging.LogFactory</code> (in Hibernate 3.2.x) or from
* <code>org.slf4j.LoggerFactory</code> (in Hibernate 3.3.x).
* @author Adam Warski (adam at warski dot org)
*/
public class YLogManager {
private Method getLogMethod;
private Class argClass;
private YLogManager() {
ClassLoader cl = YLogManager.class.getClassLoader();
try {
Class<?> logFactoryClass = cl.loadClass("org.apache.commons.logging.LogFactory");
try {
getLogMethod = logFactoryClass.getMethod("getLog", Class.class);
argClass = Object.class;
} catch (NoSuchMethodException e) {
throw new AuditException("No 'getLog' method in org.apache.commons.logging.LogFactory.");
}
} catch (ClassNotFoundException e) {
try {
Class<?> loggerFactoryClass = cl.loadClass("org.slf4j.LoggerFactory");
try {
getLogMethod = loggerFactoryClass.getMethod("getLogger", Class.class);
argClass = String.class;
} catch (NoSuchMethodException e1) {
throw new AuditException("No 'getLogger' method in org.slf4j.LoggerFactory.");
}
} catch (ClassNotFoundException e1) {
throw new AuditException("No org.apache.commons.logging.LogFactory or org.slf4j.LoggerFactory found.");
}
}
}
public YLog getLog(Class<?> cls) {
try {
return new YLog(getLogMethod.invoke(null, cls), argClass);
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
//
private static YLogManager instance;
public static synchronized YLogManager getLogManager() {
if (instance == null) {
instance = new YLogManager();
}
return instance;
}
}