#!/usr/bin/env groovy
/*
 * This file will annotate all loggers in the system witha Sentry Handler to
 * make sure that important errors are getting surfaced off the instance
 */

import io.sentry.jul.SentryHandler
import java.util.logging.*

SentryHandler sentry = new SentryHandler()
/* Default everything to the warning level, no need for INFO */
sentry.level = Level.WARNING

LogManager.logManager.loggerNames.each { loggerName ->
    def manager = LogManager.logManager.getLogger(loggerName)

    boolean found = false
    manager.handlers.each { handler ->
        if (handler.class == SentryHandler) {
            found = true
        }
    }

    if (!found) {
        println "Adding Sentry to ${loggerName}"
        manager.addHandler(sentry)
    }
}

Add a SentryHandler to all logger instances inside of the Jenkins instance on boot
Add a SentryHandler to all logger instances inside of the Jenkins instance on boot

I attempted to incorporate via
`-Djava.util.logging.config.file=/path/to/app.properties` by adding the
sentry-1.5.0.jar into /var/jenkins_home/war/WEB-INF/libs. Unfortunately it
looks like that's not added to the classpath early enough.

This script will not work unless jackson-core.jar and sentry.jar are added into
war/WEB-INF/libs
