1

slf4j と logback を使用するように jetty を構成しました。バージョン 8.x

この場所http://dev.eclipse.org/mhonarc/lists/jetty-users/msg02859.htmlによると、これらのクラスをコンテキストごとに jetty のサーバー クラスのリストに追加できるため、Web アプリケーションはslf4j サーバー クラス。

展開する戦争ごとにこれを行いたくありません。デプロイされた webapps のクラスローダーで使用できないサーバーのすべてのクラスとリソース (デフォルトで $JETTY_HOME/resources/logback.xml が webapps に表示される) を一度だけ構成することは可能ですか?

4

1 に答える 1

1

はい、 webappsの展開ライフサイクルに参加するクラスを持つことができます。

クラスの例:

package example.deploy.logging.config;

import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.webapp.WebAppContext;

public class LoggingConfigBinding implements AppLifeCycle.Binding
{
    public String[] getBindingTargets()
    {
        return new String[]
        { "deploying" };
    }

    public void processBinding(Node node, App app) throws Exception
    {
        ContextHandler handler = app.getContextHandler();
        if (handler == null)
        {
            throw new NullPointerException("No Handler created for App: " + app);
        }

        if (handler instanceof WebAppContext)
        {
            WebAppContext webapp = (WebAppContext)handler;
            webapp.addSystemClass("org.slf4j.");
        }
    }
}

次に、それをDeploymentManagerにロードする XML の一部を取得します。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <Ref id="DeploymentManager">
    <Call name="addLifeCycleBinding">
      <Arg>
        <New class="example.deploy.logging.config.LoggingConfigBinding">
        </New>
      </Arg>
    </Call>
  </Ref>
</Configure>

より完全な例については、Jetty の Logback でのログのふるい分けを参照してください(注: logback は slf4j ロギングの実装です)。

于 2013-01-28T17:45:51.747 に答える