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.LoggingLevel;
020 import org.apache.camel.Processor;
021 import org.apache.camel.processor.Logger;
022 import org.apache.camel.processor.LoggingErrorHandler;
023 import org.apache.camel.spi.RouteContext;
024 import org.apache.commons.logging.Log;
025 import org.apache.commons.logging.LogFactory;
026
027 /**
028 * Uses the {@link Logger} as an error handler, will log at <tt>ERROR</tt> level by default.
029 *
030 * @version $Revision: 765920 $
031 */
032 public class LoggingErrorHandlerBuilder extends ErrorHandlerBuilderSupport {
033 private Log log = LogFactory.getLog(Logger.class);
034 private LoggingLevel level = LoggingLevel.ERROR;
035
036 public LoggingErrorHandlerBuilder() {
037 }
038
039 public LoggingErrorHandlerBuilder(final Log log) {
040 this.log = log;
041 }
042
043 public LoggingErrorHandlerBuilder(final Log log, final LoggingLevel level) {
044 this.log = log;
045 this.level = level;
046 }
047
048 public boolean supportTransacted() {
049 return false;
050 }
051
052 public Processor createErrorHandler(final RouteContext routeContext, final Processor processor) {
053 LoggingErrorHandler handler = new LoggingErrorHandler(processor, log, level);
054 configure(handler);
055 return handler;
056 }
057
058 public LoggingLevel getLevel() {
059 return level;
060 }
061
062 public void setLevel(final LoggingLevel level) {
063 this.level = level;
064 }
065
066 public Log getLog() {
067 return log;
068 }
069
070 public void setLog(final Log log) {
071 this.log = log;
072 }
073
074 public LoggingErrorHandlerBuilder level(final LoggingLevel level) {
075 this.level = level;
076 return this;
077 }
078
079 public LoggingErrorHandlerBuilder log(final Log log) {
080 this.log = log;
081 return this;
082 }
083
084 }