REQ-2010: 更新xxl-job日志
This commit is contained in:
parent
e5c1caade1
commit
65130a0336
@ -6,16 +6,19 @@ import ch.qos.logback.core.encoder.Encoder;
|
||||
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
|
||||
import com.xxl.job.core.log.XxlJobFileAppender;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
*/
|
||||
public class XxlAppender<E> extends UnsynchronizedAppenderBase<E> {
|
||||
|
||||
protected Encoder<E> encoder;
|
||||
private final ReentrantLock lock = new ReentrantLock(false);
|
||||
private Encoder<E> encoder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setLayout(Layout<E> layout) {
|
||||
LayoutWrappingEncoder<E> lwe = new LayoutWrappingEncoder<E>();
|
||||
LayoutWrappingEncoder<E> lwe = new LayoutWrappingEncoder<>();
|
||||
lwe.setLayout(layout);
|
||||
lwe.setContext(context);
|
||||
this.encoder = lwe;
|
||||
@ -28,7 +31,16 @@ public class XxlAppender<E> extends UnsynchronizedAppenderBase<E> {
|
||||
if (encoder == null) return;
|
||||
byte[] bytes = encoder.encode(event);
|
||||
String message = new String(bytes);
|
||||
lock.lock();
|
||||
try {
|
||||
XxlJobFileAppender.appendLog(logFileName, message);
|
||||
} catch (Exception e) {
|
||||
//noinspection CallToPrintStackTrace
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user