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.model.LoggingLevel; 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: 1532 $ 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 ErrorHandlerBuilder copy() { 049 LoggingErrorHandlerBuilder answer = new LoggingErrorHandlerBuilder(); 050 answer.setLog(getLog()); 051 answer.setLevel(getLevel()); 052 return answer; 053 } 054 055 public Processor createErrorHandler(final RouteContext routeContext, final Processor processor) { 056 LoggingErrorHandler handler = new LoggingErrorHandler(processor, log, level); 057 configure(handler); 058 return handler; 059 } 060 061 public LoggingLevel getLevel() { 062 return level; 063 } 064 065 public void setLevel(final LoggingLevel level) { 066 this.level = level; 067 } 068 069 public Log getLog() { 070 return log; 071 } 072 073 public void setLog(final Log log) { 074 this.log = log; 075 } 076 077 public LoggingErrorHandlerBuilder level(final LoggingLevel level) { 078 this.level = level; 079 return this; 080 } 081 082 public LoggingErrorHandlerBuilder log(final Log log) { 083 this.log = log; 084 return this; 085 } 086 087 }