Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 572145 - [Passage][Floating] extend logging #678

Merged
merged 2 commits into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bundles/org.eclipse.passage.lbc.base/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: .
Require-Bundle: javax.servlet;bundle-version="0.0.0",
org.eclipse.osgi;bundle-version="0.0.0",
org.eclipse.passage.lic.base;bundle-version="0.0.0",
Expand Down
1 change: 1 addition & 0 deletions bundles/org.eclipse.passage.lbc.jetty/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: .
Require-Bundle: org.eclipse.osgi.services;bundle-version="0.0.0",
org.eclipse.passage.lbc.base;bundle-version="1.1.1",
org.eclipse.passage.lic.net;bundle-version="1.0.100",
Expand Down
3 changes: 2 additions & 1 deletion bundles/org.eclipse.passage.lbc.jetty/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
OSGI-INF/,\
about.html
about.html,\
config/
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG"
packages="org.eclipse.passage.lbc.internal.base">
packages="org.eclipse.passage.lbc.internal.base,org.eclipse.passage.lbc.internal.jetty,org.eclipse.passage.lic.internal.jetty,org.eclipse.passage.lic.internal.net">

<Appenders>

Expand All @@ -15,9 +15,9 @@
<RollingFile name="logs-FLS"
fileName="logs/fl-server.log" filePattern="fl-server.%i.log.gz">
<PatternLayout>
<pattern>%d{HH:mm:ss} %p %c{1.} [%t]: %m%n</pattern>
<pattern>%d{HH:mm:ss} %p %c{3.} [%t] %m%n</pattern>
</PatternLayout>
<SizeBasedTriggeringPolicy size="500" />
<SizeBasedTriggeringPolicy size="500000" />
</RollingFile>
</Route>
<Route ref="Console" key="Audit" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,30 @@
*******************************************************************************/
package org.eclipse.passage.lbc.internal.jetty;

import java.nio.file.Path;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.passage.lbc.internal.base.FlotingRequestHandled;
import org.eclipse.passage.lbc.internal.base.EagerFloatingState;
import org.eclipse.passage.lbc.internal.base.FlotingRequestHandled;
import org.eclipse.passage.lbc.internal.base.api.FloatingState;
import org.eclipse.passage.lic.internal.base.logging.Logging;
import org.eclipse.passage.lic.internal.jetty.JettyHandler;
import org.eclipse.passage.lic.internal.jetty.JettyServer;
import org.eclipse.passage.lic.internal.net.connect.Port;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;

public class JettyActivator implements BundleActivator {

private final JettyServer jetty;
private final FloatingState state = new EagerFloatingState();
private final FloatingState state;

public JettyActivator() {
jetty = new JettyServer(this::handler);
configureLogging();
this.jetty = new JettyServer(this::handler);
this.state = new EagerFloatingState();
}

@Override
Expand All @@ -45,4 +52,14 @@ private JettyHandler handler() {
return new JettyHandler(request -> new FlotingRequestHandled(new StatedRequest(request, state)).get());
}

private void configureLogging() {
new Logging(this::logConfig).configure();
}

private Path logConfig() throws Exception {
return FileLocator.getBundleFile(FrameworkUtil.getBundle(getClass())).toPath()//
.resolve("config") //$NON-NLS-1$
.resolve("log4j2.xml"); //$NON-NLS-1$
}

}
4 changes: 3 additions & 1 deletion bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.passage.lic.api;bundle-version="1.0.0";visibility:=reexport
Require-Bundle: org.eclipse.passage.lic.api;bundle-version="1.0.0";visibility:=reexport,
org.apache.logging.log4j;bundle-version="2.8.2"
Export-Package: org.eclipse.passage.lic.internal.base;
x-friends:="org.eclipse.passage.lbc.base,
org.eclipse.passage.lic.base.tests,
Expand Down Expand Up @@ -76,6 +77,7 @@ Export-Package: org.eclipse.passage.lic.internal.base;
org.eclipse.passage.lic.net,
org.eclipse.passage.loc.products.core,
org.eclipse.passage.loc.products.emfforms",
org.eclipse.passage.lic.internal.base.logging;x-friends:="org.eclipse.passage.lbc.jetty,org.eclipse.passage.lac.jetty",
org.eclipse.passage.lic.internal.base.observatory;x-internal:=true,
org.eclipse.passage.lic.internal.base.registry;x-friends:="org.eclipse.passage.lbc.base,org.eclipse.passage.seal.demo.tests,org.eclipse.passage.lic.hc.tests",
org.eclipse.passage.lic.internal.base.requirements;x-friends:="org.eclipse.passage.lic.equinox,org.eclipse.passage.lic.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.internal.base.logging;

import java.io.FileInputStream;
import java.nio.file.Path;

import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Configurator;

public final class Logging {

private final ConfigSupplier config;

public Logging(ConfigSupplier config) {
this.config = config;
}

@SuppressWarnings("resource")
public void configure() {
try {
ConfigurationSource source = new ConfigurationSource(new FileInputStream(config.get().toFile()));
Configurator.initialize(getClass().getClassLoader().getParent(), source);
} catch (Exception e) {
System.err.println("Failed to configure logging"); //$NON-NLS-1$
e.printStackTrace();
}
}

public static interface ConfigSupplier {

Path get() throws Exception;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
import java.util.Objects;
import java.util.function.Supplier;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.passage.lic.internal.jetty.i18n.Messages;
import org.eclipse.passage.lic.internal.net.connect.Port;

public final class JettyServer {

private final Logger logger = Log.getLogger(JettyServer.class);
private final Logger log = LogManager.getLogger(getClass());
private final Supplier<JettyHandler> handler;
private Server server;

Expand All @@ -37,23 +37,25 @@ public void launch(Port port) throws JettyException {
server = new Server(port.get().get());
server.setHandler(handler.get());
server.start();
logger.info(String.format(Messages.started, port.get()));
} catch (Exception exception) {
throw new JettyException(//
String.format(Messages.error_onstart, exception.getClass(), exception.getMessage()), //
exception);
log.info(String.format(Messages.started, port.get().get()));
} catch (Exception e) {
logAndRethrow(e, Messages.error_onstart);
}
}

public void terminate() throws JettyException {
try {
server.stop();
logger.info(String.format(Messages.stopped));
} catch (Exception exception) {
throw new JettyException(//
String.format(Messages.error_onstop, exception.getClass(), exception.getMessage()), //
exception);
log.info(String.format(Messages.stopped));
} catch (Exception e) {
logAndRethrow(e, Messages.error_onstop);
}
}

private void logAndRethrow(Exception e, String template) throws JettyException {
String message = String.format(template, e.getClass(), e.getMessage());
log.error(message, e);
throw new JettyException(message, e);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</configIni>

<launcherArgs>
<programArgs>-os ${target.os} -ws ${target.ws} -arch ${target.arch} -consoleLog -console
<programArgs>-os ${target.os} -ws ${target.ws} -arch ${target.arch} -consoleLog -console -server.port=8090
</programArgs>
<vmArgs>-Declipse.ignoreApp=true -Dosgi.noShutdown=true
</vmArgs>
Expand Down