/
SentryGrailsPlugin.groovy
47 lines (38 loc) · 1.62 KB
/
SentryGrailsPlugin.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
import grails.util.Environment
import net.kencochrane.raven.log4j.SentryAppender
import org.apache.log4j.Level
import org.apache.log4j.Logger
class SentryGrailsPlugin {
def version = "0.1"
def grailsVersion = "2.0 > *"
def author = "Benoit Hediard"
def authorEmail = "ben@benorama.com"
def title = "Sentry Plugin"
def description = "The Sentry Plugin allows your Grails application to use Sentry exception error tracking and aggregation."
def documentation = "https://github.com/benorama/grails-sentry"
def license = "APACHE"
def organization = [ name: "AgoraPulse", url: "http://www.agorapulse.com/" ]
def issueManagement = [ system: "github", url: "https://github.com/benorama/grails-sentry/issues" ]
def scm = [ url: "https://github.com/benorama/grails-sentry" ]
def doWithApplicationContext = { applicationContext ->
def config = application.config.grails?.plugin?.sentry
if (config && config.dsn && isEnabled(config)) {
def appender = new SentryAppender(sentryDsn: config.dsn, threshold: config.threshold ?: Level.WARN)
appender.activateOptions()
Logger.rootLogger.addAppender(appender)
}
}
// PRIVATE
private static boolean isEnabled(config) {
boolean configEnabled = false
if (config) {
// default enabled for PROD
configEnabled = (Environment.current == Environment.PRODUCTION)
// if config specified, use that instead
if (config.containsKey('enabled')) {
configEnabled = config.enabled
}
}
configEnabled
}
}