Project

General

Profile

Download (1.77 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
	private static final String CDM_LOGFILE = "cdm.logfile";
33

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

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

    
63
}
(3-3/3)