Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LogStage |
|
| 1.0;1 |
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 | 2 | private Log log = LogFactory.getLog(LogStage.class); |
34 | ||
35 | /** | |
36 | * Creates a new LogStage. | |
37 | */ | |
38 | 2 | public LogStage() { |
39 | 2 | } |
40 | ||
41 | /** | |
42 | * Logs the point at which preprocessing runs. | |
43 | */ | |
44 | public void preprocess() throws StageException { | |
45 | 2 | super.preprocess(); |
46 | 2 | log.info("Stage " + this.getClass().getName() + " preprocessing."); |
47 | 2 | } |
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 | 160 | log.info("Processing object " + obj); |
55 | 160 | this.emit(obj); |
56 | 160 | } |
57 | ||
58 | /** | |
59 | * Logs tht point at which postprocessing runs | |
60 | */ | |
61 | public void postprocess() throws StageException { | |
62 | 2 | log.info("Stage " + this.getClass().getName() + " postprocessing."); |
63 | 2 | } |
64 | ||
65 | /** | |
66 | * Logs the point at which stage resources are released. | |
67 | */ | |
68 | public void release() { | |
69 | 2 | log.info("Stage " + this.getClass().getName() + " released."); |
70 | 2 | } |
71 | ||
72 | /** | |
73 | * Sets the logger. | |
74 | */ | |
75 | public synchronized void setLog(Log log) { | |
76 | 0 | this.log = log; |
77 | 0 | } |
78 | ||
79 | /** | |
80 | * Sets the logger based upon the log name. | |
81 | */ | |
82 | public synchronized void setLog(String logName) { | |
83 | 0 | this.log = LogFactory.getLog(logName); |
84 | 0 | } |
85 | ||
86 | /** | |
87 | * Sets the logger based upon the specified class. | |
88 | */ | |
89 | public synchronized void setLog(Class clazz) { | |
90 | 0 | this.log = LogFactory.getLog(clazz); |
91 | 0 | } |
92 | } |