Commit 05c38493 authored by Marco Descher's avatar Marco Descher 🏔

[15819] Use getContext() in RocketchatAppender

parent 000f6cda
Pipeline #11304 failed with stages
in 1 minute and 3 seconds
......@@ -2,65 +2,67 @@ package ch.elexis.core.logback.rocketchat;
import java.io.IOException;
import ch.elexis.core.logback.rocketchat.internal.IntegrationPostHandler;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
public class RocketchatAppender extends AppenderBase<ILoggingEvent> {
private String event;
private String integrationUrl;
private String identification;
private String attachmentBased;
@Override
public void start(){
if (identification == null) {
identification = "logback";
public void start() {
if (getContext().getProperty("identification") == null) {
getContext().putProperty("identification", "logback");
addInfo("No <identification> parameter defined, defaulting to logback.");
}
super.start();
}
@Override
protected void append(ILoggingEvent eventObject){
protected void append(ILoggingEvent eventObject) {
try {
new IntegrationPostHandler(eventObject, identification,
Boolean.valueOf(attachmentBased)).post(integrationUrl);
String integrationUrl = getContext().getProperty("integrationUrl");
if (integrationUrl == null || integrationUrl.length() == 0) {
return;
}
String identification = getContext().getProperty("identification");
boolean attachmentBased = (getContext().getProperty("attachmentBased") == null) ? true
: Boolean.valueOf(getContext().getProperty("attachmentBased"));
new IntegrationPostHandler(eventObject, identification, attachmentBased).post(integrationUrl);
} catch (IOException ex) {
addError("Error posting to integrationUrl [" + integrationUrl + "]", ex);
addError("Error posting to integrationUrl [" + getContext().getProperty("integrationUrl") + "]", ex);
}
}
public String getEvent(){
return event;
public String getEvent() {
return getContext().getProperty("event");
}
public void setEvent(String event){
this.event = event;
public void setEvent(String event) {
getContext().putProperty("event", event);
}
public String getIntegrationUrl(){
return integrationUrl;
public String getIntegrationUrl() {
return getContext().getProperty("integrationUrl");
}
public void setIntegrationUrl(String integrationUrl){
this.integrationUrl = integrationUrl;
public void setIntegrationUrl(String integrationUrl) {
addInfo("Changing integration url ...");
getContext().putProperty("integrationUrl", integrationUrl);
}
public String getIdentification(){
return identification;
public String getIdentification() {
return getContext().getProperty("identification");
}
public void setIdentification(String identification){
this.identification = identification;
public void setIdentification(String identification) {
getContext().putProperty("identification", identification);
}
public String getAttachmentBased(){
return attachmentBased;
public String getAttachmentBased() {
return getContext().getProperty("attachmentBased");
}
public void setAttachmentBased(String attachmentBased){
this.attachmentBased = attachmentBased;
public void setAttachmentBased(String attachmentBased) {
getContext().putProperty("attachmentBased", attachmentBased);
}
}
package ch.elexis.core.logback.rocketchat;
package ch.elexis.core.logback.rocketchat.internal;
import java.io.IOException;
import java.net.HttpURLConnection;
......@@ -34,7 +34,7 @@ public class IntegrationPostHandler {
this.attachment = attachment;
}
public int post(String url) throws MalformedURLException, IOException{
public int post(String url) throws MalformedURLException, IOException{
Level logLevel = eventObject.getLevel();
if (logLevel == null) {
logLevel = Level.INFO;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment