Project

General

Profile

Download (3.9 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2020 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.server.logging;
10

    
11
import org.eclipse.jetty.server.Handler;
12
import org.eclipse.jetty.webapp.WebAppContext;
13
import org.slf4j.bridge.SLF4JBridgeHandler;
14

    
15
import eu.etaxonomy.cdm.server.instance.CdmInstance;
16

    
17
/**
18
 * The technique used in this class is based on the example
19
 * for a jetty server which uses a deployment manager, explained
20
 * in http://www.eclipse.org/jetty/documentation/jetty-9/index.html#example-logging-logback-centralized
21
 * In our situation of an embedded jetty which manages the cdm-webapp instance directly the
22
 * configuration need to be a bit different.
23
 *
24
 * The config files of the official example can found on github:
25
 * https://github.com/jetty-project/jetty-webapp-logging/
26
 *
27
 * @author a.kohlbecker
28
 * @since Jun 10, 2020
29
 */
30
public class LoggingConfigurator {
31

    
32
    public void configureServer() {
33
        // Configure logging (1)
34

    
35
        // v20190813   > https://github.com/jetty-project/jetty-webapp-logging/blob/jetty-webapp-logging-9.4.20.v20190813/jetty-webapp-logging/src/main/config/etc/jetty-jul-to-slf4j.xml
36
        // Apr 2, 2020 > https://github.com/jetty-project/jetty-webapp-logging/blob/master/jetty-webapp-logging/src/main/config/etc/jetty-jul-to-slf4j.xml
37
        SLF4JBridgeHandler.removeHandlersForRootLogger();
38
        SLF4JBridgeHandler.install();
39
        // >
40
        // jetty-webapp-logging-9.4.20.v20190813-config/resources/jetty-logging.properties
41
        System.setProperty("org.eclipse.jetty.util.log.class", org.eclipse.jetty.util.log.Slf4jLog.class.getName());
42

    
43
    }
44

    
45
    public Handler configureWebApp(WebAppContext cdmWebappContext, CdmInstance instance) {
46

    
47
        // v20190813   > https://github.com/jetty-project/jetty-webapp-logging/blob/jetty-webapp-logging-9.4.20.v20190813/jetty-webapp-logging/src/main/config/etc/jetty-webapp-logging.xml
48
        // Apr 2, 2020 > https://github.com/jetty-project/jetty-webapp-logging/blob/master/jetty-webapp-logging/src/main/java/org/eclipse/jetty/webapp/logging/CentralizedWebAppLoggingBinding.java
49
        // ---> adds the org.eclipse.jetty.webapp.logging.CentralizedWebAppLoggingBinding
50
        // (from jetty-webapp-logging-9.4.20.v20190813.jar) to the DeploymentManager,
51
        // in the  cdm-server we are not using the DeploymentManager so
52
        // this needs to be done per web app explicitly:
53
        cdmWebappContext.getSystemClasspathPattern().add("org.apache.log4j.");  //log4j12  probably not needed anymore
54
        cdmWebappContext.getSystemClasspathPattern().add("org.apache.logging.log4j."); //log4j2
55
        cdmWebappContext.getSystemClasspathPattern().add("org.slf4j.");
56
        cdmWebappContext.getSystemClasspathPattern().add("org.apache.commons.logging.");
57

    
58
        // UPDATE:
59
        // in the latest version of the jetty-webapp-logging (Apr 2, 2020) the classnames are also removed from the ServerClasspathPatterns:
60
        cdmWebappContext.getServerClasspathPattern().add("-org.apache.log4j.");
61
        cdmWebappContext.getServerClasspathPattern().add("-org.apache.logging.log4j.");
62
        cdmWebappContext.getServerClasspathPattern().add("-org.slf4j.");
63
        cdmWebappContext.getServerClasspathPattern().add("-org.apache.commons.logging.");
64

    
65

    
66
        // v20190813  > https://github.com/jetty-project/jetty-webapp-logging/blob/jetty-webapp-logging-9.4.20.v20190813/jetty-webapp-logging/src/etc/jetty-mdc-handler.xml
67
        // Apr 2, 2020 > https://github.com/jetty-project/jetty-webapp-logging/blob/master/jetty-webapp-logging/src/main/config/etc/jetty-mdc-handler.xml
68
        InstanceLogWrapper instanceLogger = new InstanceLogWrapper(instance.getName());
69
        instanceLogger.setHandler(cdmWebappContext); // wrap context handler
70
        return instanceLogger;
71
    }
72
}
(2-2/2)