1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.pipeline.stage; 19 20 import org.apache.commons.pipeline.StageException; 21 import org.apache.commons.pipeline.stage.BaseStage; 22 import java.util.Queue; 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 27 /** 28 * A do-nothing implementation of Stage that simply logs the state of processing. 29 * and each object seen by its {@link #process(Object)} method. 30 * Useful for debugging purposes. 31 */ 32 public class LogStage extends BaseStage { 33 private Log log = LogFactory.getLog(LogStage.class); 34 35 /** 36 * Creates a new LogStage. 37 */ 38 public LogStage() { 39 } 40 41 /** 42 * Logs the point at which preprocessing runs. 43 */ 44 public void preprocess() throws StageException { 45 super.preprocess(); 46 log.info("Stage " + this.getClass().getName() + " preprocessing."); 47 } 48 49 /** 50 * Logs the current state of an object on the queue and passes the 51 * object unchanged to the next stage in the pipeline. 52 */ 53 public void process(Object obj) throws StageException { 54 log.info("Processing object " + obj); 55 this.emit(obj); 56 } 57 58 /** 59 * Logs tht point at which postprocessing runs 60 */ 61 public void postprocess() throws StageException { 62 log.info("Stage " + this.getClass().getName() + " postprocessing."); 63 } 64 65 /** 66 * Logs the point at which stage resources are released. 67 */ 68 public void release() { 69 log.info("Stage " + this.getClass().getName() + " released."); 70 } 71 72 /** 73 * Sets the logger. 74 */ 75 public synchronized void setLog(Log log) { 76 this.log = log; 77 } 78 79 /** 80 * Sets the logger based upon the log name. 81 */ 82 public synchronized void setLog(String logName) { 83 this.log = LogFactory.getLog(logName); 84 } 85 86 /** 87 * Sets the logger based upon the specified class. 88 */ 89 public synchronized void setLog(Class clazz) { 90 this.log = LogFactory.getLog(clazz); 91 } 92 }