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 ch.qos.logback.core.encoder.LayoutWrappingEncoder;
|
||||||
import com.xxl.job.core.log.XxlJobFileAppender;
|
import com.xxl.job.core.log.XxlJobFileAppender;
|
||||||
|
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yanglin
|
* @author yanglin
|
||||||
*/
|
*/
|
||||||
public class XxlAppender<E> extends UnsynchronizedAppenderBase<E> {
|
public class XxlAppender<E> extends UnsynchronizedAppenderBase<E> {
|
||||||
|
|
||||||
protected Encoder<E> encoder;
|
private final ReentrantLock lock = new ReentrantLock(false);
|
||||||
|
private Encoder<E> encoder;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void setLayout(Layout<E> layout) {
|
public void setLayout(Layout<E> layout) {
|
||||||
LayoutWrappingEncoder<E> lwe = new LayoutWrappingEncoder<E>();
|
LayoutWrappingEncoder<E> lwe = new LayoutWrappingEncoder<>();
|
||||||
lwe.setLayout(layout);
|
lwe.setLayout(layout);
|
||||||
lwe.setContext(context);
|
lwe.setContext(context);
|
||||||
this.encoder = lwe;
|
this.encoder = lwe;
|
||||||
@ -28,7 +31,16 @@ public class XxlAppender<E> extends UnsynchronizedAppenderBase<E> {
|
|||||||
if (encoder == null) return;
|
if (encoder == null) return;
|
||||||
byte[] bytes = encoder.encode(event);
|
byte[] bytes = encoder.encode(event);
|
||||||
String message = new String(bytes);
|
String message = new String(bytes);
|
||||||
XxlJobFileAppender.appendLog(logFileName, message);
|
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