Permalink
Browse files

Merge branch '2.0.x' of https://github.com/grails/grails-core into 2.0.x

  • Loading branch information...
2 parents 53efdbb + 422dbac commit 715bf5b7762cb1a77f684665e0c5086d73fec2d1 Jonathan Pearlin committed Jan 16, 2012
@@ -308,15 +308,14 @@ public Object doCall() {
ModuleRevisionId.newInstance("commons-fileupload", "commons-fileupload", "1.2.2"),
ModuleRevisionId.newInstance("oro", "oro", "2.0.8"),
// data source
-
- ModuleRevisionId.newInstance("commons-dbcp", "commons-dbcp", java5compatible ? "1.3": "1.4"),
ModuleRevisionId.newInstance("commons-pool", "commons-pool", "1.5.6"),
+ ModuleRevisionId.newInstance("commons-dbcp", "commons-dbcp", java5compatible ? "1.3": "1.4"),
ModuleRevisionId.newInstance("com.h2database", "h2", "1.2.147"),
// JSP support
ModuleRevisionId.newInstance("javax.servlet", "jstl", "1.1.2"),
ModuleRevisionId.newInstance("xpp3", "xpp3_min", "1.1.4c")
};
- registerDependencies(dependencyManager, runtimeDependenciesMethod, runtimeDependencies, "commons-pool");
+ registerDependencies(dependencyManager, runtimeDependenciesMethod, runtimeDependencies);
if(java5compatible) {
registerDependencies(dependencyManager, runtimeDependenciesMethod, new ModuleRevisionId[] { ModuleRevisionId.newInstance("javax.xml", "jaxb-api", "2.0"), }, "commons-pool");
}
@@ -81,6 +81,14 @@ class Log4jConfig {
}
}
+ def propertyMissing(String name) {
+ if (LAYOUTS.containsKey(name)) {
+ return LAYOUTS[name].newInstance()
+ }
+
+ LogLog.error "Property missing when configuring log4j: $name"
+ }
+
def methodMissing(String name, args) {
if (APPENDERS.containsKey(name) && args) {
def constructorArgs = args[0] instanceof Map ? args[0] : [:]
@@ -375,16 +383,16 @@ class RootLog4jConfig {
Logger root
Log4jConfig config
- def RootLog4jConfig(root, config) {
+ RootLog4jConfig(root, config) {
this.root = root
this.config = config
}
def debug(Object[] appenders = null) {
- setLevelAndAppender(Level.DEBUG,appenders)
+ setLevelAndAppender(Level.DEBUG, appenders)
}
- private setLevelAndAppender(Level level,Object[] appenders) {
+ private setLevelAndAppender(Level level, Object[] appenders) {
root.level = level
for (appName in appenders) {
Appender app
@@ -401,34 +409,34 @@ class RootLog4jConfig {
}
def info(Object[] appenders = null) {
- setLevelAndAppender(Level.INFO,appenders)
+ setLevelAndAppender(Level.INFO, appenders)
}
def warn(Object[] appenders = null) {
- setLevelAndAppender(Level.WARN,appenders)
+ setLevelAndAppender(Level.WARN, appenders)
}
def trace(Object[] appenders = null) {
- setLevelAndAppender(Level.TRACE,appenders)
+ setLevelAndAppender(Level.TRACE, appenders)
}
def all(Object[] appenders = null) {
- setLevelAndAppender(Level.ALL,appenders)
+ setLevelAndAppender(Level.ALL, appenders)
}
def error(Object[] appenders = null) {
- setLevelAndAppender(Level.ERROR,appenders)
+ setLevelAndAppender(Level.ERROR, appenders)
}
def fatal(Object[] appenders = null) {
- setLevelAndAppender(Level.FATAL,appenders)
+ setLevelAndAppender(Level.FATAL, appenders)
}
def off(Object[] appenders = null) {
- setLevelAndAppender(Level.OFF,appenders)
+ setLevelAndAppender(Level.OFF, appenders)
}
- void setProperty(String s, Object o) {
+ void setProperty(String s, o) {
root."$s" = o
}
}
@@ -19,10 +19,14 @@ import grails.util.Environment
import org.apache.log4j.Appender
import org.apache.log4j.ConsoleAppender
+import org.apache.log4j.FileAppender
+import org.apache.log4j.HTMLLayout
import org.apache.log4j.Level
import org.apache.log4j.LogManager
import org.apache.log4j.Logger
+import org.apache.log4j.SimpleLayout
import org.apache.log4j.WriterAppender
+import org.apache.log4j.xml.XMLLayout
import org.codehaus.groovy.grails.plugins.log4j.Log4jConfig
class Log4jDslTests extends GroovyTestCase {
@@ -31,29 +35,26 @@ class Log4jDslTests extends GroovyTestCase {
protected void setUp() {
super.setUp()
- System.setProperty(Environment.KEY, "")
+ setEnv ''
+ LogManager.resetConfiguration()
}
protected void tearDown() {
- System.setProperty(Environment.KEY, "")
+ super.tearDown()
+ setEnv ''
}
void testSingleDebugStatement() {
- LogManager.resetConfiguration()
-
log4jConfig.configure {
debug 'org.hibernate.SQL'
}
- def hibernateLogger = Logger.getLogger("org.hibernate.SQL")
- assertEquals hibernateLogger.level, Level.DEBUG
+ assertEquals Logger.getLogger("org.hibernate.SQL").level, Level.DEBUG
}
void testEnvironmentSpecificLogging() {
- System.setProperty(Environment.KEY, "production")
-
- LogManager.resetConfiguration()
+ setEnv 'production'
log4jConfig.configure {
environments {
@@ -72,18 +73,14 @@ class Log4jDslTests extends GroovyTestCase {
}
}
- def hibernateLogger = Logger.getLogger("org.hibernate.SQL")
- assertEquals hibernateLogger.level, Level.ERROR
+ assertEquals Logger.getLogger("org.hibernate.SQL").level, Level.ERROR
}
void testCustomEnvironment() {
- System.setProperty(Environment.KEY, "firstCustomEnv")
+ setEnv 'firstCustomEnv'
- LogManager.resetConfiguration()
-
- Log4jConfig config = new Log4jConfig()
- config.configure {
+ log4jConfig.configure {
environments {
development {
trace 'org.hibernate.SQL'
@@ -100,24 +97,18 @@ class Log4jDslTests extends GroovyTestCase {
}
}
- def hibernateLogger = Logger.getLogger("org.hibernate.SQL")
- assertEquals hibernateLogger.level, Level.WARN
-
+ assertEquals Logger.getLogger("org.hibernate.SQL").level, Level.WARN
}
void testTraceLevel() {
- LogManager.resetConfiguration()
-
log4jConfig.configure {
trace 'org.hibernate.SQL'
}
- def hibernateLogger = Logger.getLogger("org.hibernate.SQL")
- assertEquals hibernateLogger.level, Level.TRACE
+ assertEquals Logger.getLogger("org.hibernate.SQL").level, Level.TRACE
}
void testConfigureRootLogger() {
- LogManager.resetConfiguration()
log4jConfig.configure {
root {
@@ -131,7 +122,7 @@ class Log4jDslTests extends GroovyTestCase {
assertEquals Level.DEBUG, r.level
assertTrue r.additivity
Appender a = r.allAppenders.nextElement()
- assertEquals "stdout",a.name
+ assertEquals "stdout", a.name
LogManager.resetConfiguration()
@@ -150,7 +141,7 @@ class Log4jDslTests extends GroovyTestCase {
assertEquals Level.TRACE, r.level
assertTrue r.additivity
a = r.allAppenders.nextElement()
- assertEquals "writerAppender",a.name
+ assertEquals "writerAppender", a.name
LogManager.resetConfiguration()
@@ -170,13 +161,12 @@ class Log4jDslTests extends GroovyTestCase {
assertTrue r.additivity
Enumeration appenders = r.allAppenders
a = appenders.nextElement()
- assertEquals "writerAppender",a.name
+ assertEquals "writerAppender", a.name
a = appenders.nextElement()
- assertEquals "stdout",a.name
+ assertEquals "stdout", a.name
}
void testSensibleDefaults() {
- LogManager.resetConfiguration()
log4jConfig.configure {
debug 'org.codehaus.groovy.grails.web.servlet',
@@ -208,8 +198,6 @@ class Log4jDslTests extends GroovyTestCase {
void testCustomAppender() {
- LogManager.resetConfiguration()
-
def consoleAppender
log4jConfig.configure {
appenders {
@@ -241,7 +229,6 @@ class Log4jDslTests extends GroovyTestCase {
}
void testCustomAppenderWithInstance() {
- LogManager.resetConfiguration()
log4jConfig.configure {
appenders {
@@ -270,8 +257,6 @@ class Log4jDslTests extends GroovyTestCase {
*/
void testRootLoggerModification() {
- LogManager.resetConfiguration()
-
log4jConfig.configure { root ->
root.level = Level.DEBUG
}
@@ -281,21 +266,17 @@ class Log4jDslTests extends GroovyTestCase {
}
void testConfigFromCollection() {
- LogManager.resetConfiguration()
-
log4jConfig.configure([{
debug 'org.hibernate.SQL'
},
{
warn 'org.hibernate.SQL'
}])
- def hibernateLogger = Logger.getLogger("org.hibernate.SQL")
- assertEquals Level.WARN, hibernateLogger.level
+ assertEquals Level.WARN, Logger.getLogger("org.hibernate.SQL").level
}
void testConfigFromMap() {
- LogManager.resetConfiguration()
def configData = [:]
configData.main = {
@@ -306,7 +287,48 @@ class Log4jDslTests extends GroovyTestCase {
}
log4jConfig.configure(configData)
- def hibernateLogger = Logger.getLogger("org.hibernate.SQL")
- assertEquals Level.WARN, hibernateLogger.level
+ assertEquals Level.WARN, Logger.getLogger("org.hibernate.SQL").level
+ }
+
+ void testLayouts() {
+
+ log4jConfig.configure {
+ appenders {
+ file name: 'fileXml', layout: xml, file: 'log.xml'
+ file name: 'fileHtml', layout: html, file: 'log.html'
+ file name: 'fileSimple', layout: simple, file: 'simple.log'
+ }
+ root {
+ debug 'fileXml', 'fileHtml', 'fileSimple'
+ }
+ }
+
+ Logger root = Logger.rootLogger
+
+ Appender appender = root.getAppender('fileXml')
+ assert appender instanceof FileAppender
+ FileAppender fa = appender
+ assert 'log.xml' == fa.file
+
+ assert fa.layout instanceof XMLLayout
+ assert fa.name == 'fileXml'
+
+ appender = root.getAppender('fileHtml')
+ assert appender instanceof FileAppender
+ fa = appender
+ assert 'log.html' == fa.file
+ assert fa.layout instanceof HTMLLayout
+ assert fa.name == 'fileHtml'
+
+ appender = root.getAppender('fileSimple')
+ assert appender instanceof FileAppender
+ fa = appender
+ assert 'simple.log' == fa.file
+ assert fa.layout instanceof SimpleLayout
+ assert fa.name == 'fileSimple'
+ }
+
+ private void setEnv(String name) {
+ System.setProperty Environment.KEY, name
}
}

0 comments on commit 715bf5b

Please sign in to comment.