Project

General

Profile

Revision f0cf14eb

IDf0cf14ebe5283f76a2dcf2134f0eb3aefab51e6f
Parent 887cb9a0
Child d45008d0

Added by Andreas Kohlbecker about 4 years ago

fix #6249 prefixig all logappender with instance (bean) name and disabling per instance log files

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/config/DataSourceConfigurer.java
138 138
    @Bean
139 139
    public DataSource dataSource() {
140 140

  
141

  
142

  
143 141
        String beanName = findProperty(ATTRIBUTE_DATASOURCE_NAME, true);
144 142
        String jndiName = null;
145 143
        if(this.dataSource == null){
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/config/LoggingConfigurer.java
10 10
package eu.etaxonomy.cdm.remote.config;
11 11

  
12 12
import java.io.IOException;
13
import java.util.Enumeration;
13 14

  
15
import org.apache.log4j.Appender;
14 16
import org.apache.log4j.Logger;
15 17
import org.apache.log4j.PatternLayout;
16 18
import org.apache.log4j.RollingFileAppender;
17 19
import org.springframework.beans.factory.InitializingBean;
20
import org.springframework.beans.factory.annotation.Autowired;
18 21
import org.springframework.context.annotation.Configuration;
19 22

  
20 23
/**
......
25 28
@Configuration
26 29
public class LoggingConfigurer extends AbstractWebApplicationConfigurer implements InitializingBean  {
27 30

  
31
    @Autowired
32
    private DataSourceProperties dataSourceProperties = null;
33

  
28 34
    /**
29 35
     *
30 36
     */
......
35 41
     */
36 42
    private static final String CDM_LOGFILE = "cdm.logfile";
37 43

  
38
    protected void configureLogFile() {
44
    private void configureLogFile() {
39 45
        PatternLayout layout = new PatternLayout("%d %p [%c] - %m%n");
40 46
        String logFile = findProperty(CDM_LOGFILE, false);
41 47
        if (logFile == null) {
......
54 60
        }
55 61
    }
56 62

  
63
    /**
64
     *
65
     */
66
    private void configureInstanceNamePrefix() {
67
        String instanceName = dataSourceProperties.getCurrentDataSourceId();
68
        String patternPrefix = "[" + instanceName + "] ";
69

  
70
        @SuppressWarnings("unchecked")
71
        Enumeration<Appender> appenders = Logger.getRootLogger().getAllAppenders();
72
        while(appenders.hasMoreElements()){
73
            Appender appender = appenders.nextElement();
74
            if(appender != null){
75
                if(appender.getLayout() instanceof PatternLayout){
76
                    PatternLayout layout = (PatternLayout)appender.getLayout();
77
                    String conversionPattern = layout.getConversionPattern();
78
                    if(!conversionPattern.startsWith(patternPrefix)){
79
                        layout.setConversionPattern(patternPrefix + conversionPattern);
80
                    }
81
                }
82
            }
83
        }
84

  
85
    }
86

  
57 87
    /* (non-Javadoc)
58 88
     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
59 89
     */
60 90
    @Override
61 91
    public void afterPropertiesSet() throws Exception {
62
        configureLogFile();
92
        // per instance logfiles disabled, see #6249
93
        // configureLogFile();
94
        configureInstanceNamePrefix();
63 95
    }
64 96

  
65 97

  
66

  
67 98
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)