1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.logging.log4j.io.internal;
19
20 import java.io.FilterWriter;
21 import java.io.IOException;
22 import java.io.Writer;
23
24 import org.apache.logging.log4j.Level;
25 import org.apache.logging.log4j.Marker;
26 import org.apache.logging.log4j.io.CharStreamLogger;
27 import org.apache.logging.log4j.spi.ExtendedLogger;
28
29
30
31
32
33
34 public class InternalFilterWriter extends FilterWriter {
35
36 private final CharStreamLogger logger;
37 private final String fqcn;
38
39 public InternalFilterWriter(final Writer out, final ExtendedLogger logger, final String fqcn, final Level level,
40 final Marker marker) {
41 super(out);
42 this.logger = new CharStreamLogger(logger, level, marker);
43 this.fqcn = fqcn;
44 }
45
46 @Override
47 public void close() throws IOException {
48 this.out.close();
49 this.logger.close(this.fqcn);
50 }
51
52 @Override
53 public void flush() throws IOException {
54 this.out.flush();
55 }
56
57 @Override
58 public String toString() {
59 return "{writer=" + this.out + '}';
60 }
61
62 @Override
63 public void write(final char[] cbuf) throws IOException {
64 this.out.write(cbuf);
65 this.logger.put(this.fqcn, cbuf, 0, cbuf.length);
66 }
67
68 @Override
69 public void write(final char[] cbuf, final int off, final int len) throws IOException {
70 this.out.write(cbuf, off, len);
71 this.logger.put(this.fqcn, cbuf, off, len);
72 }
73
74 @Override
75 public void write(final int c) throws IOException {
76 this.out.write(c);
77 this.logger.put(this.fqcn, (char) c);
78 }
79
80 @Override
81 public void write(final String str) throws IOException {
82 this.out.write(str);
83 this.logger.put(this.fqcn, str, 0, str.length());
84 }
85
86 @Override
87 public void write(final String str, final int off, final int len) throws IOException {
88 this.out.write(str, off, len);
89 this.logger.put(this.fqcn, str, off, len);
90 }
91 }