Permalink
Browse files

Merge branch 'master' of github.com:grails/grails-core

  • Loading branch information...
2 parents a775536 + e4b0807 commit 74a583bd42692f28a486a053b6c0a4022c586126 @graemerocher graemerocher committed Apr 26, 2012
@@ -36,23 +36,17 @@
* @since 2.0
*/
@SuppressWarnings("serial")
-public class GrailsLog4jLoggerAdapter extends MarkerIgnoringBase {
-
+public class GrailsLog4jLoggerAdapter extends MarkerIgnoringBase implements org.slf4j.Logger {
+ private static final long serialVersionUID = 1L;
static final String FQCN = GrailsLog4jLoggerAdapter.class.getName();
- private Logger log4jLogger;
- private String name;
+ private final Logger log4jLogger;
public GrailsLog4jLoggerAdapter(org.apache.log4j.Logger logger) {
this.log4jLogger = logger;
this.name = logger.getName();
}
- @Override
- public String getName() {
- return name;
- }
-
public boolean isTraceEnabled() {
return log4jLogger.isTraceEnabled();
}
@@ -62,15 +56,15 @@ public void trace(String msg) {
}
public void trace(String format, Object arg) {
- logMessageFormat(TRACE, getMessageFormat(format, arg));
+ logMessageFormat(TRACE, format, arg);
}
public void trace(String format, Object arg1, Object arg2) {
- logMessageFormat(TRACE, getMessageFormat(format, arg1, arg2));
+ logMessageFormat(TRACE, format, arg1, arg2);
}
public void trace(String format, Object[] argArray) {
- logMessageFormat(TRACE, getMessageFormat(format, argArray));
+ logMessageFormat(TRACE, format, argArray);
}
public void trace(String msg, Throwable t) {
@@ -82,19 +76,19 @@ public boolean isDebugEnabled() {
}
public void debug(String msg) {
- logMessage(DEBUG, msg);
+ logMessage(DEBUG, msg, null);
}
public void debug(String format, Object arg) {
- logMessageFormat(DEBUG, getMessageFormat(format, arg));
+ logMessageFormat(DEBUG, format, arg);
}
public void debug(String format, Object arg1, Object arg2) {
- logMessageFormat(DEBUG, getMessageFormat(format, arg1, arg2));
+ logMessageFormat(DEBUG, format, arg1, arg2);
}
public void debug(String format, Object[] argArray) {
- logMessageFormat(DEBUG, getMessageFormat(format, argArray));
+ logMessageFormat(DEBUG, format, argArray);
}
public void debug(String msg, Throwable t) {
@@ -106,19 +100,19 @@ public boolean isInfoEnabled() {
}
public void info(String msg) {
- logMessage(INFO, msg);
+ logMessage(INFO, msg, null);
}
public void info(String format, Object arg) {
- logMessageFormat(INFO, getMessageFormat(format, arg));
+ logMessageFormat(INFO, format, arg);
}
public void info(String format, Object arg1, Object arg2) {
- logMessageFormat(INFO, getMessageFormat(format, arg1, arg2));
+ logMessageFormat(INFO, format, arg1, arg2);
}
public void info(String format, Object[] argArray) {
- logMessageFormat(INFO, getMessageFormat(format, argArray));
+ logMessageFormat(INFO, format, argArray);
}
public void info(String msg, Throwable t) {
@@ -130,19 +124,19 @@ public boolean isWarnEnabled() {
}
public void warn(String msg) {
- logMessage(WARN, msg);
+ logMessage(WARN, msg, null);
}
public void warn(String format, Object arg) {
- logMessageFormat(WARN, getMessageFormat(format, arg));
+ logMessageFormat(WARN, format, arg);
}
public void warn(String format, Object[] argArray) {
- logMessageFormat(WARN, getMessageFormat(format, argArray));
+ logMessageFormat(WARN, format, argArray);
}
public void warn(String format, Object arg1, Object arg2) {
- logMessageFormat(WARN, getMessageFormat(format, arg1, arg2));
+ logMessageFormat(WARN, format, arg1, arg2);
}
public void warn(String msg, Throwable t) {
@@ -154,49 +148,47 @@ public boolean isErrorEnabled() {
}
public void error(String msg) {
- logMessage(ERROR, msg);
+ logMessage(ERROR, msg, null);
}
public void error(String format, Object arg) {
- logMessageFormat(ERROR, getMessageFormat(format, arg));
+ logMessageFormat(ERROR, format, arg);
}
public void error(String format, Object arg1, Object arg2) {
- logMessageFormat(ERROR, getMessageFormat(format, arg1, arg2));
+ logMessageFormat(ERROR, format, arg1, arg2);
}
public void error(String format, Object[] argArray) {
- logMessageFormat(ERROR, getMessageFormat(format, argArray));
+ logMessageFormat(ERROR, format, argArray);
}
public void error(String msg, Throwable t) {
logMessage(ERROR, msg, t);
}
- private FormattingTuple getMessageFormat(String format, Object... args) {
+ private final FormattingTuple getMessageFormat(final String format, final Object... args) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
cleanIfException(ft.getThrowable());
return ft;
}
- private Throwable cleanIfException(Throwable t) {
+ private final Throwable cleanIfException(final Throwable t) {
if (t != null) {
new DefaultStackTraceFilterer().filter(t, true);
}
return t;
}
- private void logMessageFormat(Level level, FormattingTuple ft) {
- log4jLogger.log(FQCN, level, ft.getMessage(), ft.getThrowable());
- }
-
- private void logMessage(Level level, String msg) {
- logMessage(level, msg, null);
+ private final void logMessageFormat(final Level level, final String format, final Object... args) {
+ if(log4jLogger.isEnabledFor(level)) {
+ FormattingTuple ft = getMessageFormat(format, args);
+ log4jLogger.log(FQCN, level, ft.getMessage(), ft.getThrowable());
+ }
}
- private void logMessage(Level level, String msg, Throwable t) {
- Throwable filteredTrace = msg.startsWith(StackTraceFilterer.FULL_STACK_TRACE_MESSAGE) ? t : cleanIfException(t);
-
+ private final void logMessage(final Level level, final String msg, final Throwable t) {
+ Throwable filteredTrace = (t != null && log4jLogger.isEnabledFor(level) && !("StackTrace".equals(name) || (msg != null && msg.startsWith(StackTraceFilterer.FULL_STACK_TRACE_MESSAGE)))) ? cleanIfException(t) : t;
log4jLogger.log(FQCN, level, msg, filteredTrace);
}
}
@@ -39,7 +39,7 @@ protected CompilationUnit makeCompileUnit() {
ImportCustomizer importCustomizer = new ImportCustomizer();
importCustomizer.addStarImports("grails.test.mixin");
importCustomizer.addStarImports("org.junit");
- importCustomizer.addStaticStars("org.junit.Assert");
+ importCustomizer.addStaticStars("groovy.util.GroovyTestCase");
ASTTransformationCustomizer astTransformationCustomizer = new ASTTransformationCustomizer(TestFor.class);

0 comments on commit 74a583b

Please sign in to comment.