View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.log4j.spring;
17  
18  import java.util.Arrays;
19  
20  import org.apache.log4j.ConsoleAppender;
21  import org.apache.log4j.PatternLayout;
22  import org.kuali.common.util.xml.service.XmlService;
23  import org.kuali.common.util.xml.spring.XmlServiceConfig;
24  import org.springframework.beans.factory.annotation.Autowired;
25  import org.springframework.context.annotation.Bean;
26  import org.springframework.context.annotation.Configuration;
27  import org.springframework.context.annotation.Import;
28  
29  /**
30   * @deprecated
31   */
32  @Deprecated
33  @Configuration
34  @Import({ XmlServiceConfig.class })
35  public class Log4JConfig {
36  
37  	protected static final String SPRING = "org.springframework";
38  	protected static final String STDOUT = "stdout";
39  
40  	@Autowired
41  	XmlServiceConfig xmlServiceConfig;
42  
43  	@Bean
44  	public org.kuali.common.util.log4j.Log4JService log4jService() {
45  		XmlService service = xmlServiceConfig.xmlService();
46  		return new org.kuali.common.util.log4j.DefaultLog4JService(service);
47  	}
48  
49  	@Bean
50  	public org.kuali.common.util.log4j.model.Log4JContext log4JContextDefault() {
51  		return getLog4JContext(org.kuali.common.util.log4j.Log4JPatternConstants.DEFAULT, org.kuali.common.util.log4j.model.Value.INFO);
52  	}
53  
54  	@Bean
55  	public org.kuali.common.util.log4j.model.Log4JContext log4JContextTest() {
56  		return getLog4JContext(org.kuali.common.util.log4j.Log4JPatternConstants.DEBUG, org.kuali.common.util.log4j.model.Value.INFO);
57  	}
58  
59  	@Bean
60  	public org.kuali.common.util.log4j.model.Log4JContext log4JContextDebug() {
61  		return getLog4JContext(org.kuali.common.util.log4j.Log4JPatternConstants.DEBUG, org.kuali.common.util.log4j.model.Value.DEBUG);
62  	}
63  
64  	@Bean
65  	public org.kuali.common.util.log4j.model.Log4JContext log4JContextMaven() {
66  		org.kuali.common.util.log4j.model.Log4JContext context = getLog4JContext(org.kuali.common.util.log4j.Log4JPatternConstants.MAVEN,org.kuali.common.util.log4j.model.Value.INFO);
67  		// Tone down Spring logging when we are running a build
68  		org.kuali.common.util.log4j.model.Logger spring = new org.kuali.common.util.log4j.model.Logger(SPRING, new org.kuali.common.util.log4j.model.Level(org.kuali.common.util.log4j.model.Value.WARN));
69  		context.setLoggers(Arrays.asList(spring));
70  		return context;
71  	}
72  
73  	protected org.kuali.common.util.log4j.model.Log4JContext getLog4JContext(String pattern, org.kuali.common.util.log4j.model.Value value) {
74  		org.kuali.common.util.log4j.model.Param param = new org.kuali.common.util.log4j.model.param.ConversionPatternParam(pattern);
75  		org.kuali.common.util.log4j.model.Layout layout = new org.kuali.common.util.log4j.model.Layout(PatternLayout.class, param);
76  		org.kuali.common.util.log4j.model.Appender console = new org.kuali.common.util.log4j.model.Appender(STDOUT, ConsoleAppender.class, layout);
77  		org.kuali.common.util.log4j.model.AppenderRef ref = new org.kuali.common.util.log4j.model.AppenderRef(console.getName());
78  		org.kuali.common.util.log4j.model.Logger root = new org.kuali.common.util.log4j.model.Logger(ref, new org.kuali.common.util.log4j.model.Level(value));
79  		return new org.kuali.common.util.log4j.model.Log4JContext(console, root, true);
80  	}
81  }