001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.camel.builder;
018    
019    import org.apache.camel.Processor;
020    import org.apache.camel.processor.Logger;
021    import org.apache.camel.processor.LoggingErrorHandler;
022    import org.apache.camel.processor.LoggingLevel;
023    import org.apache.commons.logging.Log;
024    import org.apache.commons.logging.LogFactory;
025    
026    /**
027     * Uses the {@link Logger} as an error handler
028     *
029     * @version $Revision: 36321 $
030     */
031    public class LoggingErrorHandlerBuilder extends ErrorHandlerBuilderSupport {
032        private Log log = LogFactory.getLog(Logger.class);
033        private LoggingLevel level = LoggingLevel.INFO;
034    
035        public LoggingErrorHandlerBuilder() {
036        }
037    
038        public LoggingErrorHandlerBuilder(Log log) {
039            this.log = log;
040        }
041    
042        public LoggingErrorHandlerBuilder(Log log, LoggingLevel level) {
043            this.log = log;
044            this.level = level;
045        }
046    
047        public ErrorHandlerBuilder copy() {
048            LoggingErrorHandlerBuilder answer = new LoggingErrorHandlerBuilder();
049            answer.setLog(getLog());
050            answer.setLevel(getLevel());
051            return answer;
052        }
053    
054        public Processor createErrorHandler(Processor processor) {
055            LoggingErrorHandler handler = new LoggingErrorHandler(processor, log, level);
056            configure(handler);
057            return handler;
058        }
059    
060        public LoggingLevel getLevel() {
061            return level;
062        }
063    
064        public void setLevel(LoggingLevel level) {
065            this.level = level;
066        }
067    
068        public Log getLog() {
069            return log;
070        }
071    
072        public void setLog(Log log) {
073            this.log = log;
074        }
075    }