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