1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sf.hermesftp.utils;
26
27 import java.io.OutputStream;
28 import java.io.PrintWriter;
29 import java.io.Writer;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33
34 /***
35 * Helper class that logs server responses.
36 *
37 * @author Lars Behnke
38 */
39 public class LoggingWriter
40 extends PrintWriter {
41
42 private static final int LOG_LINE_LENGTH = 80;
43
44 private static Log log = LogFactory.getLog(LoggingWriter.class);
45
46 /***
47 * Constructor.
48 *
49 * @param out The output stream.
50 * @param flush Automatic flush
51 */
52 public LoggingWriter(OutputStream out, boolean flush) {
53 super(out, flush);
54 }
55
56 /***
57 * Constructor.
58 *
59 * @param out The output writer.
60 * @param flush Automatic flush
61 */
62 public LoggingWriter(Writer out, boolean flush) {
63 super(out, flush);
64 }
65
66 /***
67 * {@inheritDoc}
68 */
69 public void println(String text) {
70 if (log.isDebugEnabled()) {
71 String x;
72 if (text != null && text.length() >= LOG_LINE_LENGTH) {
73 x = text.substring(0, LOG_LINE_LENGTH) + " [" + (text.length() - LOG_LINE_LENGTH)
74 + " more chars]";
75 } else {
76 x = text;
77 }
78 log.debug("-->: " + x);
79 }
80 super.println(text);
81
82
83
84 }
85 }