-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLogbackGrailsPlugin.groovy
More file actions
66 lines (52 loc) · 1.92 KB
/
LogbackGrailsPlugin.groovy
File metadata and controls
66 lines (52 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import grails.plugin.logback.LogbackConfig
import grails.plugin.logback.LogbackConfigListener
import grails.util.Metadata
import java.util.logging.LogManager
import org.codehaus.groovy.grails.commons.GrailsApplication
import org.slf4j.bridge.SLF4JBridgeHandler
class LogbackGrailsPlugin {
String version = '0.4.0'
String grailsVersion = '2.0 > *'
String title = 'Logback Plugin'
String author = 'Burt Beckwith'
String authorEmail = 'burt@burtbeckwith.com'
String description = 'Replaces Log4j with Logback for logging'
String documentation = 'http://grails.org/plugin/logback'
String packaging = 'binary'
def loadBefore = ['core', 'logging']
def evict = ['groovyPages', 'logging'] // groovyPages transitively brings in grails-logging and must be added back in BuildConfig with excludes
String license = 'APACHE'
def organization = [name: 'Grails', url: 'http://grails.org/']
def issueManagement = [url: 'https://github.com/grails-plugins/grails-logback/issues']
def scm = [url: 'https://github.com/grails-plugins/grails-logback']
def doWithWebDescriptor = { xml ->
initLogging application
def mappingElement = xml.'filter-mapping'
mappingElement = mappingElement[mappingElement.size() - 1]
mappingElement + {
listener {
'listener-class'(LogbackConfigListener.name)
}
}
}
def doWithSpring = {
if (application.config?.grails?.logging?.jul?.usebridge) {
LogManager.logManager.readConfiguration new ByteArrayInputStream(".level=INFO".bytes)
SLF4JBridgeHandler.install()
}
if (application.warDeployed) {
// only initialize here if deployed as a war since doWithWebDescriptor isn't called
initLogging application
}
}
def onConfigChange = { event ->
LogbackConfig.initialize event.source
}
private void initLogging(GrailsApplication application) {
if (!Metadata.current.getApplicationName()) {
// don't configure in the plugin
return
}
LogbackConfig.initialize application.config
}
}