Project

General

Profile

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

    
12
import java.io.IOException;
13

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

    
20
/**
21
 * @author a.kohlbecker
22
 * @date 20.07.2010
23
 *
24
 */
25
@Configuration
26
public class LoggingConfigurer extends AbstractWebApplicationConfigurer implements InitializingBean  {
27

    
28
    /**
29
     *
30
     */
31
    private static final String ROLLING_FILE_APPENDER = "rollingFileAppender";
32

    
33
    /**
34
     * see also <code>eu.etaxonomy.cdm.server.instance.SharedAttributes</code>
35
     */
36
    private static final String CDM_LOGFILE = "cdm.logfile";
37

    
38
    protected void configureLogFile() {
39
        PatternLayout layout = new PatternLayout("%d %p [%c] - %m%n");
40
        String logFile = findProperty(CDM_LOGFILE, false);
41
        if (logFile == null) {
42
            logger.info("No logfile specified, runing without.");
43
            return;
44
        }
45
        try {
46
            RollingFileAppender appender = new RollingFileAppender(layout, logFile);
47
            appender.setName(ROLLING_FILE_APPENDER);
48
            appender.setMaxBackupIndex(3);
49
            appender.setMaxFileSize("2MB");
50
            Logger.getRootLogger().addAppender(appender);
51
            logger.info("logging to :" + logFile);
52
        } catch (IOException e) {
53
            logger.error("Creating RollingFileAppender failed:", e);
54
        }
55
    }
56

    
57
    /* (non-Javadoc)
58
     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
59
     */
60
    @Override
61
    public void afterPropertiesSet() throws Exception {
62
        configureLogFile();
63
    }
64

    
65

    
66

    
67
}
(4-4/4)