001/**
002 * Copyright 2010-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.common.util.log4j.spring;
017
018import java.util.Arrays;
019
020import org.apache.log4j.ConsoleAppender;
021import org.apache.log4j.PatternLayout;
022import org.kuali.common.util.xml.service.XmlService;
023import org.kuali.common.util.xml.spring.XmlServiceConfig;
024import org.springframework.beans.factory.annotation.Autowired;
025import org.springframework.context.annotation.Bean;
026import org.springframework.context.annotation.Configuration;
027import org.springframework.context.annotation.Import;
028
029/**
030 * @deprecated
031 */
032@Deprecated
033@Configuration
034@Import({ XmlServiceConfig.class })
035public class Log4JConfig {
036
037        protected static final String SPRING = "org.springframework";
038        protected static final String STDOUT = "stdout";
039
040        @Autowired
041        XmlServiceConfig xmlServiceConfig;
042
043        @Bean
044        public org.kuali.common.util.log4j.Log4JService log4jService() {
045                XmlService service = xmlServiceConfig.xmlService();
046                return new org.kuali.common.util.log4j.DefaultLog4JService(service);
047        }
048
049        @Bean
050        public org.kuali.common.util.log4j.model.Log4JContext log4JContextDefault() {
051                return getLog4JContext(org.kuali.common.util.log4j.Log4JPatternConstants.DEFAULT, org.kuali.common.util.log4j.model.Value.INFO);
052        }
053
054        @Bean
055        public org.kuali.common.util.log4j.model.Log4JContext log4JContextTest() {
056                return getLog4JContext(org.kuali.common.util.log4j.Log4JPatternConstants.DEBUG, org.kuali.common.util.log4j.model.Value.INFO);
057        }
058
059        @Bean
060        public org.kuali.common.util.log4j.model.Log4JContext log4JContextDebug() {
061                return getLog4JContext(org.kuali.common.util.log4j.Log4JPatternConstants.DEBUG, org.kuali.common.util.log4j.model.Value.DEBUG);
062        }
063
064        @Bean
065        public org.kuali.common.util.log4j.model.Log4JContext log4JContextMaven() {
066                org.kuali.common.util.log4j.model.Log4JContext context = getLog4JContext(org.kuali.common.util.log4j.Log4JPatternConstants.MAVEN,org.kuali.common.util.log4j.model.Value.INFO);
067                // Tone down Spring logging when we are running a build
068                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));
069                context.setLoggers(Arrays.asList(spring));
070                return context;
071        }
072
073        protected org.kuali.common.util.log4j.model.Log4JContext getLog4JContext(String pattern, org.kuali.common.util.log4j.model.Value value) {
074                org.kuali.common.util.log4j.model.Param param = new org.kuali.common.util.log4j.model.param.ConversionPatternParam(pattern);
075                org.kuali.common.util.log4j.model.Layout layout = new org.kuali.common.util.log4j.model.Layout(PatternLayout.class, param);
076                org.kuali.common.util.log4j.model.Appender console = new org.kuali.common.util.log4j.model.Appender(STDOUT, ConsoleAppender.class, layout);
077                org.kuali.common.util.log4j.model.AppenderRef ref = new org.kuali.common.util.log4j.model.AppenderRef(console.getName());
078                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));
079                return new org.kuali.common.util.log4j.model.Log4JContext(console, root, true);
080        }
081}