forked from grails-plugins/grails-logback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogbackGrailsPlugin.groovy
65 lines (51 loc) · 1.74 KB
/
LogbackGrailsPlugin.groovy
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
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.1.1'
String grailsVersion = '2.0 > *'
String title = 'Logback Plugin'
String author = 'Burt Beckwith'
String authorEmail = '[email protected]'
String description = 'Replaces Log4j with Logback for logging'
String documentation = 'http://grails.org/plugin/logback'
String packaging = 'binary'
List loadBefore = ['core', 'log4j']
List evict = ['log4j']
String license = 'APACHE'
def issueManagement = [system: 'JIRA', url: 'http://jira.grails.org/browse/GPLOGBACK']
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
}
}