Skip to content

Commit

Permalink
Refactored Log to ILog with Log's being an implementation using Commo…
Browse files Browse the repository at this point in the history
…ns Logging.
  • Loading branch information
mhanes committed Aug 15, 2009
1 parent 7eec56e commit ba53470
Show file tree
Hide file tree
Showing 25 changed files with 232 additions and 111 deletions.
Expand Up @@ -5,7 +5,7 @@
import java.util.ResourceBundle;
import java.util.UnknownFormatConversionException;

public class Log {
public class CommonsResourceLog implements ILog {

private org.apache.commons.logging.Log logger = null;

Expand All @@ -17,24 +17,30 @@ public class Log {
private static String MESSAGE_KEY = "MessageKey: ";
private static String DEFAULT_BUNDLE_NAME = "logMessages";

Log(org.apache.commons.logging.Log logger) {
CommonsResourceLog(org.apache.commons.logging.Log logger) {
this(logger, DEFAULT_BUNDLE_NAME, Locale.getDefault());
}

Log(org.apache.commons.logging.Log logger, String bundleName) {
CommonsResourceLog(org.apache.commons.logging.Log logger, String bundleName) {
this(logger, bundleName, Locale.getDefault());
}

Log(org.apache.commons.logging.Log logger, String bundleName, Locale locale) {
CommonsResourceLog(org.apache.commons.logging.Log logger, String bundleName, Locale locale) {
this.logger = logger;
this.bundleName = bundleName;
setLocale(locale);
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#getMessage(java.lang.String)
*/
public String getMessage(String key) {
return getMessage(key, (Object) null);
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#getMessage(java.lang.String, java.lang.Object)
*/
public String getMessage(String key, Object... args) {
if (bundle != null) {
try {
Expand All @@ -54,10 +60,16 @@ public String getMessage(String key, Object... args) {
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#getLocale()
*/
public Locale getLocale() {
return locale;
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#setLocale(java.util.Locale)
*/
public void setLocale(Locale locale) {
this.locale = locale;
try {
Expand All @@ -68,35 +80,53 @@ public void setLocale(Locale locale) {
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#getBundleName()
*/
public String getBundleName() {
return bundleName;
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#setBundleName(java.lang.String)
*/
public void setBundleName(String bundleName) {
this.bundleName = bundleName;
this.bundle = ResourceBundle.getBundle(bundleName, locale);
}

// Debug

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#debug(java.lang.String)
*/
public void debug(String messageKey) {
if (logger.isDebugEnabled()) {
logger.debug(getMessage(messageKey));
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#debug(java.lang.String, java.lang.Throwable)
*/
public void debug(String messageKey, Throwable t) {
if (logger.isDebugEnabled()) {
logger.debug(getMessage(messageKey), t);
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#debug(java.lang.String, java.lang.Object)
*/
public void debug(String messageKey, Object... args) {
if (logger.isDebugEnabled()) {
logger.debug(getMessage(messageKey, args));
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#debug(java.lang.String, java.lang.Throwable, java.lang.Object)
*/
public void debug(String messageKey, Throwable t, Object... args) {
if (logger.isDebugEnabled()) {
logger.debug(getMessage(messageKey, args), t);
Expand All @@ -105,24 +135,36 @@ public void debug(String messageKey, Throwable t, Object... args) {

// info

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#info(java.lang.String)
*/
public void info(String messageKey) {
if (logger.isInfoEnabled()) {
logger.info(getMessage(messageKey));
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#info(java.lang.String, java.lang.Throwable)
*/
public void info(String messageKey, Throwable t) {
if (logger.isInfoEnabled()) {
logger.info(getMessage(messageKey), t);
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#info(java.lang.String, java.lang.Object)
*/
public void info(String messageKey, Object... args) {
if (logger.isInfoEnabled()) {
logger.info(getMessage(messageKey, args));
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#info(java.lang.String, java.lang.Throwable, java.lang.Object)
*/
public void info(String messageKey, Throwable t, Object... args) {
if (logger.isInfoEnabled()) {
logger.info(getMessage(messageKey, args), t);
Expand All @@ -131,24 +173,36 @@ public void info(String messageKey, Throwable t, Object... args) {

// warn

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#warn(java.lang.String)
*/
public void warn(String messageKey) {
if (logger.isWarnEnabled()) {
logger.warn(getMessage(messageKey));
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#warn(java.lang.String, java.lang.Throwable)
*/
public void warn(String messageKey, Throwable t) {
if (logger.isWarnEnabled()) {
logger.warn(getMessage(messageKey), t);
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#warn(java.lang.String, java.lang.Object)
*/
public void warn(String messageKey, Object... args) {
if (logger.isWarnEnabled()) {
logger.warn(getMessage(messageKey, args));
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#warn(java.lang.String, java.lang.Throwable, java.lang.Object)
*/
public void warn(String messageKey, Throwable t, Object... args) {
if (logger.isWarnEnabled()) {
logger.warn(getMessage(messageKey, args), t);
Expand All @@ -157,31 +211,46 @@ public void warn(String messageKey, Throwable t, Object... args) {

// error

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#error(java.lang.String)
*/
public void error(String messageKey) {
if (logger.isErrorEnabled()) {
logger.error(getMessage(messageKey));
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#error(java.lang.String, java.lang.Throwable)
*/
public void error(String messageKey, Throwable t) {
if (logger.isErrorEnabled()) {
logger.error(getMessage(messageKey), t);
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#error(java.lang.String, java.lang.Object)
*/
public void error(String messageKey, Object... args) {
if (logger.isErrorEnabled()) {
logger.error(getMessage(messageKey, args));
}
}

/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#error(java.lang.String, java.lang.Throwable, java.lang.Object)
*/
public void error(String messageKey, Throwable t, Object... args) {
if (logger.isErrorEnabled()) {
logger.error(getMessage(messageKey, args), t);
}
}


/* (non-Javadoc)
* @see org.jumpmind.symmetric.common.logging.ILog#error(java.lang.Throwable)
*/
public void error(Throwable t) {
if (logger.isErrorEnabled()) {
logger.error(t,t);
Expand Down
@@ -0,0 +1,53 @@
package org.jumpmind.symmetric.common.logging;

import java.util.Locale;

public interface ILog {

public abstract String getMessage(String key);

public abstract String getMessage(String key, Object... args);

public abstract Locale getLocale();

public abstract void setLocale(Locale locale);

public abstract String getBundleName();

public abstract void setBundleName(String bundleName);

public abstract void debug(String messageKey);

public abstract void debug(String messageKey, Throwable t);

public abstract void debug(String messageKey, Object... args);

public abstract void debug(String messageKey, Throwable t, Object... args);

public abstract void info(String messageKey);

public abstract void info(String messageKey, Throwable t);

public abstract void info(String messageKey, Object... args);

public abstract void info(String messageKey, Throwable t, Object... args);

public abstract void warn(String messageKey);

public abstract void warn(String messageKey, Throwable t);

public abstract void warn(String messageKey, Object... args);

public abstract void warn(String messageKey, Throwable t, Object... args);

public abstract void error(String messageKey);

public abstract void error(String messageKey, Throwable t);

public abstract void error(String messageKey, Object... args);

public abstract void error(String messageKey, Throwable t, Object... args);

public abstract void error(Throwable t);

}
Expand Up @@ -5,7 +5,7 @@
public class LogFactory {

@SuppressWarnings("unchecked")
public static Log getLog(Class clazz) throws LogConfigurationException {
return new Log(org.apache.commons.logging.LogFactory.getLog(clazz));
public static ILog getLog(Class clazz) throws LogConfigurationException {
return new CommonsResourceLog(org.apache.commons.logging.LogFactory.getLog(clazz));
}
}
Expand Up @@ -24,7 +24,7 @@
import java.util.ArrayList;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.symmetric.common.logging.Log;
import org.jumpmind.symmetric.common.logging.ILog;
import org.jumpmind.symmetric.common.logging.LogFactory;

/**
Expand All @@ -35,15 +35,15 @@
public class DynamicPropertiesFiles extends ArrayList<String> {

private static final long serialVersionUID = 1L;
private static Log logger = LogFactory.getLog(DynamicPropertiesFiles.class);
private static ILog log = LogFactory.getLog(DynamicPropertiesFiles.class);

public DynamicPropertiesFiles() {
File file = new File(System.getProperty("user.dir"), "symmetric.properties");
if (file.exists() && file.isFile()) {
try {
add(file.toURL().toExternalForm());
} catch (MalformedURLException e) {
logger.error(e);
log.error(e);
}
}
if (!StringUtils.isBlank(System.getProperty("symmetric.override.properties.file.1"))) {
Expand Down

0 comments on commit ba53470

Please sign in to comment.