Commit 4c89d59e authored by Marco Descher's avatar Marco Descher 🏔

[15819] Add ElexisEnvironmentActivator

parent 76d2c857
Pipeline #11312 passed with stages
in 2 minutes and 25 seconds
<configuration>
<contextName>ES</contextName>
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<statusListener
class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<contextListener
class="info.elexis.server.core.logging.ClassloadingLoggerContextListener" />
<include file="${user.home}/elexis-server/logback-addition.xml" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<appender name="rocketchatAppender"
class="ch.elexis.core.logback.rocketchat.RocketchatAppender">
<!-- deny all events with a level below WARN, that is INFO, TRACE and DEBUG -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
</appender>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%t] %d %-5level %logger{36} - %msg%n</pattern>
</encoder>
......@@ -19,7 +29,8 @@
<appender name="ROLLING"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${user.home}/elexis-server/logs/elexis-server.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<maxHistory>28</maxHistory>
<fileNamePattern>${user.home}/elexis-server/logs/elexis-server-%d{yyyy-MM-dd}.%i.log.zip
</fileNamePattern>
......@@ -36,7 +47,8 @@
<appender name="ROLLING_WARN"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${user.home}/elexis-server/logs/elexis-server.WARN.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<rollingPolicy
class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${user.home}/elexis-server/logs/elexis-server-%d{yyyy-MM-dd}.%i.WARN.log.zip
</fileNamePattern>
<minIndex>1</minIndex>
......@@ -59,7 +71,8 @@
<appender name="ROLLING_ERROR"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${user.home}/elexis-server/logs/elexis-server.ERROR.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<rollingPolicy
class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${user.home}/elexis-server/logs/elexis-server-%d{yyyy-MM-dd}.%i.ERROR.log.zip
</fileNamePattern>
<minIndex>1</minIndex>
......@@ -82,16 +95,21 @@
<logger name="org.eclipse" level="INFO" />
<logger name="org.apache" level="INFO" />
<logger name="se.ugli.bigqueue" level="INFO" />
<logger name="ch.medelexis.server.connector.rockethealth" level="TRACE" />
<logger name="ch.medelexis.server.connector.rockethealth"
level="TRACE" />
<logger name="ca.uhn.fhir" level="INFO" />
<logger name="org.apache.shiro.session.mgt.DefaultSessionManager" level="INFO" />
<logger name="org.eclipse.persistence.logging.metadata" level="WARN" />
<logger
name="org.apache.shiro.session.mgt.DefaultSessionManager" level="INFO" />
<logger name="org.eclipse.persistence.logging.metadata"
level="WARN" />
<root level="${root.level:-DEBUG}">
<appender-ref ref="STDOUT" />
<appender-ref ref="ROLLING" />
<appender-ref ref="ROLLING_WARN" />
<appender-ref ref="ROLLING_ERROR" />
<!-- will be replace with async appender in ElexisEnvironmentActivator -->
<appender-ref ref="rocketchatAppender" />
</root>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" activate="activate" name="info.elexis.server.core.eenv.ElexisEnvironmentActivator">
<reference cardinality="1..1" field="contextService" interface="ch.elexis.core.services.IContextService" name="contextService"/>
<reference cardinality="1..1" field="elexisEnvironmentService" interface="ch.elexis.core.eenv.IElexisEnvironmentService" name="elexisEnvironmentService"/>
<implementation class="info.elexis.server.core.eenv.ElexisEnvironmentActivator"/>
</scr:component>
\ No newline at end of file
......@@ -10,6 +10,8 @@ import org.eclipse.equinox.app.IApplicationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.elexis.core.services.IContextService;
import ch.elexis.core.utils.OsgiServiceUtil;
import info.elexis.server.core.contrib.ApplicationShutdownRegistrar;
import info.elexis.server.core.contrib.IApplicationShutdownListener;
......@@ -28,7 +30,9 @@ public class Application implements IApplication {
@Override
public Object start(IApplicationContext context) throws Exception{
log.info("Starting {} ...", getClass().getName());
String stationId = OsgiServiceUtil.getService(IContextService.class).get().getStationIdentifier();
log.info("{}: system starting", stationId);
log.info("Settings: TimeZone [{}], user.language [{}], user.region [{}]",
TimeZone.getDefault().getID(), System.getProperty("user.language"),
......@@ -43,13 +47,13 @@ public class Application implements IApplication {
}
if (restart) {
log.info("Restarting {} ...", getClass().getName());
log.warn("{}: system restarting", stationId);
// give all services time to shutdown
Thread.sleep(2000);
return IApplication.EXIT_RESTART;
}
log.info("Stopping {} ...", getClass().getName());
log.warn("{}: system shutting down", stationId);
return IApplication.EXIT_OK;
}
......
package info.elexis.server.core.eenv;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.elexis.core.eenv.IElexisEnvironmentService;
import ch.elexis.core.services.IContextService;
import ch.qos.logback.classic.AsyncAppender;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Appender;
@Component
public class ElexisEnvironmentActivator {
@Reference
private IElexisEnvironmentService elexisEnvironmentService;
@Reference
private IContextService contextService;
@Activate
public void activate() {
String hostname = elexisEnvironmentService.getHostname();
activateRocketChatLogAppender(hostname);
}
private void activateRocketChatLogAppender(String hostname) {
String rocketchatIntegrationToken = elexisEnvironmentService.getProperty("EE_RC_ES_INTEGRATION_WEBHOOK_TOKEN");
String rocketchatIntegrationUrl = "https://" + hostname + "/chat/hooks/" + rocketchatIntegrationToken;
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger slf4jRootLogger = lc.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) slf4jRootLogger;
Appender<ILoggingEvent> rocketchatAppender = rootLogger.getAppender("rocketchatAppender");
if (rocketchatAppender != null) {
/**
* Logs events >= Level.WARN
*/
rocketchatAppender.getContext().putProperty("integrationUrl", rocketchatIntegrationUrl);
rocketchatAppender.getContext().putProperty("identification", contextService.getStationIdentifier());
rootLogger.detachAppender(rocketchatAppender);
AsyncAppender asyncAppender = new AsyncAppender();
asyncAppender.setContext(rootLogger.getLoggerContext());
asyncAppender.addAppender(rocketchatAppender);
asyncAppender.start();
rootLogger.addAppender(asyncAppender);
} else {
LoggerFactory.getLogger(getClass()).error("Could not get rocketchat appender from root logger");
}
}
}
\ No newline at end of file
......@@ -68,4 +68,12 @@
version="0.0.0"
unpack="false"/>
<plugin
id="ch.elexis.core.logback.rocketchat"
download-size="0"
install-size="0"
version="0.0.0"
fragment="true"
unpack="false"/>
</feature>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde?>
<!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl -->
<target name="Elexis-Server" sequenceNumber="1569323530">
<target name="Elexis-Server" sequenceNumber="1569507192">
<locations>
<location includeMode="slicer" includeAllPlatforms="true" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
<unit id="org.osgi.framework.system.packages.extra" version="1.0.0.20190124-1239"/>
......@@ -77,7 +77,7 @@
<unit id="com.eclipsesource.jaxrs.provider.swagger.feature.feature.group" version="1.1.1.201905211243"/>
<unit id="com.eclipsesource.jaxrs.provider.multipart.feature.feature.group" version="2.2.0.201905211243"/>
<unit id="ch.rgw.utility" version="3.8.0.20190906-1311"/>
<unit id="ch.elexis.core" version="3.8.0.20190911-1253"/>
<unit id="ch.elexis.core" version="3.8.0.20190926-0852"/>
<unit id="ch.elexis.core.l10n" version="3.8.0.20190911-1253"/>
<unit id="ch.elexis.core.importer.div" version="3.2.0.20190906-1311"/>
<unit id="ch.elexis.core.hl7.v2x" version="3.2.0.20190819-0833"/>
......@@ -87,13 +87,14 @@
<unit id="ch.elexis.core.test" version="1.0.0.20190920-0803"/>
<unit id="ch.elexis.core.jpa" version="1.0.0.20190920-0944"/>
<unit id="ch.elexis.core.jpa.datasource" version="1.0.0.20190829-1235"/>
<unit id="ch.elexis.core.jpa.entities" version="1.0.0.20190903-1809"/>
<unit id="ch.elexis.core.jpa.entities" version="1.0.0.20190925-1045"/>
<unit id="ch.elexis.core.jpa.logging.slf4j" version="1.0.0.20181009-1221"/>
<unit id="ch.elexis.core.model" version="1.0.0.20190902-1312"/>
<unit id="ch.elexis.core.model" version="1.0.0.20190926-0809"/>
<unit id="ch.elexis.core.jcifs" version="2.1.2.20190917-0933"/>
<unit id="ch.elexis.core.services" version="1.0.0.20190902-1313"/>
<unit id="ch.elexis.core.services" version="1.0.0.20190926-1347"/>
<unit id="ch.elexis.core.findings.fhir.model" version="1.0.0.20190723-1221"/>
<unit id="ch.elexis.core.tasks" version="1.0.0.20190924-0900"/>
<unit id="ch.elexis.core.tasks" version="1.0.0.20190925-0856"/>
<unit id="ch.elexis.core.logback.rocketchat" version="1.0.0.20190926-1348"/>
<unit id="org.postgresql.jdbc42" version="42.2.5"/>
<unit id="org.h2" version="1.3.170"/>
<unit id="org.jdom" version="1.1.0"/>
......@@ -109,7 +110,7 @@
<unit id="com.healthmarketscience.jackcess" version="2.1.9"/>
<unit id="org.beanshell.bsh" version="2.0.0.0b4"/>
<unit id="at.medevit.ch.artikelstamm" version="3.3.0.20190911-1115"/>
<unit id="at.medevit.ch.artikelstamm.model" version="1.0.0.20190902-1316"/>
<unit id="at.medevit.ch.artikelstamm.model" version="1.0.0.20190926-0839"/>
<unit id="ch.elexis.base.ch.ticode" version="3.2.0.20190516-0804"/>
<unit id="at.medevit.atc_codes" version="3.1.0.20190409-1536"/>
<unit id="ch.elexis.omnivore" version="3.2.0.20190430-1229"/>
......
......@@ -100,6 +100,7 @@ location "http://download.elexis.info/elexis-server/master/p2/target/" elexis-se
ch.elexis.core.services
ch.elexis.core.findings.fhir.model
ch.elexis.core.tasks
ch.elexis.core.logback.rocketchat
//
org.postgresql.jdbc42
org.h2
......
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