mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-14 01:38:00 +07:00
Changed design slightly to only defer message contents encoding
This commit is contained in:
@ -1,16 +1,21 @@
|
|||||||
package com.riiablo.logger;
|
package com.riiablo.logger;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
|
|
||||||
public class RiiabloEncoder extends SimpleEncoder {
|
public class RiiabloEncoder extends SimpleEncoder {
|
||||||
private final StringBuilder buffer = new StringBuilder(1024);
|
private final StringBuilder buffer = new StringBuilder(1024);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encode(LogEvent event, OutputStream out) {
|
public void encode(LogEvent event, OutputStream out) {
|
||||||
encodeMessage(event, out);
|
try {
|
||||||
|
encodeMessage(event, buffer);
|
||||||
|
out.write(buffer.toString().getBytes(US_ASCII));
|
||||||
|
newLine(out);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
ExceptionUtils.rethrow(t);
|
||||||
|
} finally {
|
||||||
|
buffer.setLength(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void encodeMessage(LogEvent event, OutputStream out) {
|
|
||||||
super.encode(event, out);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.riiablo.logger;
|
package com.riiablo.logger;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import org.apache.commons.lang3.ClassUtils;
|
import org.apache.commons.lang3.ClassUtils;
|
||||||
@ -15,6 +16,22 @@ public class SimpleEncoder implements Encoder {
|
|||||||
@Override
|
@Override
|
||||||
public void encode(LogEvent event, OutputStream out) {
|
public void encode(LogEvent event, OutputStream out) {
|
||||||
try {
|
try {
|
||||||
|
encodeMessage(event, buffer);
|
||||||
|
out.write(buffer.toString().getBytes(US_ASCII));
|
||||||
|
newLine(out);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
ExceptionUtils.rethrow(t);
|
||||||
|
} finally {
|
||||||
|
buffer.setLength(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void newLine(OutputStream out) throws IOException {
|
||||||
|
out.write(newLine);
|
||||||
|
out.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void encodeMessage(LogEvent event, StringBuilder buffer) {
|
||||||
buffer.append(StringUtils.rightPad(event.level().name(), 5));
|
buffer.append(StringUtils.rightPad(event.level().name(), 5));
|
||||||
buffer.append(' ');
|
buffer.append(' ');
|
||||||
buffer.append('[');
|
buffer.append('[');
|
||||||
@ -22,13 +39,5 @@ public class SimpleEncoder implements Encoder {
|
|||||||
buffer.append(']');
|
buffer.append(']');
|
||||||
buffer.append(' ');
|
buffer.append(' ');
|
||||||
buffer.append(event.message().format());
|
buffer.append(event.message().format());
|
||||||
out.write(buffer.toString().getBytes(US_ASCII));
|
|
||||||
out.write(newLine);
|
|
||||||
out.flush();
|
|
||||||
} catch (Throwable t) {
|
|
||||||
ExceptionUtils.rethrow(t);
|
|
||||||
} finally {
|
|
||||||
buffer.setLength(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user