forked from maximecharron/statistics-gatherer-plugin
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an optional dependency to the forthcoming plugin that includes the LOGBack appender to push events to the NATS pub/sub broker. LOGBack (https://logback.qos.ch/) is a very powerful and versatile logging system that allows to decouple the generation of events from the underlying transport method. A new option "Enable publish of events to LOGBack" will send all the events to LOGBack as well, so that other ways of communications can be implemented to offload all the events outside the Jenkins box. Change-Id: I595b3a1f3460443cf26c1a68d8581a247f520505
- Loading branch information
1 parent
a412491
commit 7548ea8
Showing
15 changed files
with
256 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/org/jenkins/plugins/statistics/gatherer/util/LogbackUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.jenkins.plugins.statistics.gatherer.util; | ||
|
||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.classic.util.ContextInitializer; | ||
import ch.qos.logback.core.joran.spi.JoranException; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
public class LogbackUtil { | ||
private static final String STATISTICS_GATHERER_LOGGER = "statistics-gatherer"; | ||
private static Logger logger; | ||
|
||
private static Logger getLogger(String loggerName) { | ||
LoggerContext loggerContext = new LoggerContext(); | ||
ContextInitializer contextInitializer = new ContextInitializer(loggerContext); | ||
try { | ||
String configurationUrlString = PropertyLoader.getLogbackConfigXmlUrl(); | ||
if (configurationUrlString == null) { | ||
throw new IllegalStateException("LOGBack XML configuration file not specified"); | ||
} | ||
|
||
URL configurationUrl = new URL(configurationUrlString); | ||
contextInitializer.configureByResource(configurationUrl); | ||
return loggerContext.getLogger(loggerName); | ||
} catch (JoranException e) { | ||
throw new RuntimeException("Unable to configure logger", e); | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException("Unable to find LOGBack XML configuration", e); | ||
} | ||
} | ||
|
||
public static void info(Object object) { | ||
if (PropertyLoader.getShouldSendToLogback()) { | ||
if(logger == null) { | ||
synchronized (LogbackUtil.class) { | ||
logger = getLogger(STATISTICS_GATHERER_LOGGER); | ||
} | ||
} | ||
logger.info(JSONUtil.convertToJson(object)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.