Commit 05c38493 authored by Marco Descher's avatar Marco Descher
Browse files

[15819] Use getContext() in RocketchatAppender

parent 000f6cda
Loading
Loading
Loading
Loading
+41 −39
Original line number Diff line number Diff line
@@ -2,21 +2,16 @@ 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";
		if (getContext().getProperty("identification") == null) {
			getContext().putProperty("identification", "logback");
			addInfo("No <identification> parameter defined, defaulting to logback.");
		}
		super.start();
@@ -25,42 +20,49 @@ public class RocketchatAppender extends AppenderBase<ILoggingEvent> {
	@Override
	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;
		return getContext().getProperty("event");
	}

	public void setEvent(String event) {
		this.event = event;
		getContext().putProperty("event", event);
	}

	public String getIntegrationUrl() {
		return integrationUrl;
		return getContext().getProperty("integrationUrl");
	}

	public void setIntegrationUrl(String integrationUrl) {
		this.integrationUrl = integrationUrl;
		addInfo("Changing integration url ...");
		getContext().putProperty("integrationUrl", integrationUrl);
	}

	public String getIdentification() {
		return identification;
		return getContext().getProperty("identification");
	}

	public void setIdentification(String identification) {
		this.identification = identification;
		getContext().putProperty("identification", identification);
	}

	public String getAttachmentBased() {
		return attachmentBased;
		return getContext().getProperty("attachmentBased");
	}

	public void setAttachmentBased(String attachmentBased) {
		this.attachmentBased = attachmentBased;
		getContext().putProperty("attachmentBased", attachmentBased);
	}
}
+2 −2
Original line number Diff line number Diff line
package ch.elexis.core.logback.rocketchat;
package ch.elexis.core.logback.rocketchat.internal;

import java.io.IOException;
import java.net.HttpURLConnection;