How to consolidate java.util.logging, System. (Out | err) and Jetty logging?
I read about how to make java.util.logging and System logs. (out | err) sent to slf4j:
But it takes multiple jar / classes and code to run the launcher. Basically something like:
SLF4JBridgeHandler.install() // to pipe j.u.l
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J() // to pipe System.(out|err)
I know how to add the necessary jars / classes available for the pier (just add sysout-over-slf4j.jar and jul-to-slf4j.jar to $ JETTY_HOME / lib / ext), but I don't know how I can run the code abobe on server startup to have jetty configure the consolidated outputs (sysout and jul) to slf4j. I can run this code for a webapp, but for everything to be correct it must be done by the application, not every webapp that needs this behavior.
Should it be done differently? Is there a way other than voodo?
Please do your answer for the dock version> = 8
source to share
I don't know if this will work, but have you tried it?
public class MyWebappServlet ... {
static {
// to pipe j.u.l
SLF4JBridgeHandler.install();
// to pipe System.(out|err)
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
}
...
And in your web.xml
:
<servlet>
<servlet-name>MyWebapp</servlet-name>
<servlet-class>MyWebappServlet</servlet-class>
</servlet>
It may not intercept everything from the start, but once Jetty loads your class MyWebappServlet
, the log should be redirected.
Otherwise, you will need to customize your Jetty with these two lines.
UPDATE:
There is another way - use a wrapper main()
like BCEL to start Jetty, but only after these redirects have been done.
In this case, the command line will look something like this:
java my.custom.JavaWrapper org.eclipse.jetty.start.Main [arguments]
If it can be done in jetty.sh
, then it applies to all web applications on this server instance.
source to share