本文整理汇总了Java中org.apache.twill.api.logging.LogThrowable类的典型用法代码示例。如果您正苦于以下问题:Java LogThrowable类的具体用法?Java LogThrowable怎么用?Java LogThrowable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LogThrowable类属于org.apache.twill.api.logging包,在下文中一共展示了LogThrowable类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import org.apache.twill.api.logging.LogThrowable; //导入依赖的package包/类
@Override
public JsonElement serialize(ILoggingEvent event, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();
json.addProperty("name", event.getLoggerName());
json.addProperty("host", hostname);
json.addProperty("timestamp", Long.toString(event.getTimeStamp()));
json.addProperty("level", event.getLevel().toString());
json.addProperty("className", classNameConverter.convert(event));
json.addProperty("method", methodConverter.convert(event));
json.addProperty("file", fileConverter.convert(event));
json.addProperty("line", lineConverter.convert(event));
json.addProperty("thread", event.getThreadName());
json.addProperty("message", event.getFormattedMessage());
json.addProperty("runnableName", runnableName);
if (event.getThrowableProxy() == null) {
json.add("throwable", JsonNull.INSTANCE);
} else {
json.add("throwable", context.serialize(new DefaultLogThrowable(event.getThrowableProxy()), LogThrowable.class));
}
return json;
}
示例2: onLog
import org.apache.twill.api.logging.LogThrowable; //导入依赖的package包/类
@Override
public void onLog(LogEntry logEntry) {
final LoggingEvent loggingEvent = new LoggingEvent();
loggingEvent.setTimeStamp(logEntry.getTimestamp());
loggingEvent.setLoggerName(logEntry.getLoggerName());
loggingEvent.setLevel(Level.valueOf(logEntry.getLogLevel().name()));
loggingEvent.setThreadName(logEntry.getThreadName());
Object [] formatObjects = new Object[] {logEntry.getHost(),
getSimpleClassName(logEntry.getSourceClassName()),
logEntry.getSourceMethodName(),
logEntry.getFileName(),
logEntry.getLineNumber(),logEntry.getMessage()};
loggingEvent.setMessage(MESSAGE_FORMAT.get().format(formatObjects));
// Prints the throwable and stack trace.
LogThrowable logThrowable = logEntry.getThrowable();
if (logThrowable != null) {
loggingEvent.setThrowableProxy(new ThrowableProxy(setThrowable(logThrowable)));
}
if (logger instanceof Logger) {
((Logger) logger).callAppenders(loggingEvent);
} else {
logger.info("Logger is not instance of ch.qos.logback.classic.Logger. Logger event is: {}", loggingEvent);
}
}
示例3: setThrowable
import org.apache.twill.api.logging.LogThrowable; //导入依赖的package包/类
private Throwable setThrowable(LogThrowable logThrowable) {
if (logThrowable == null) {
return null;
}
Throwable throwable = new Throwable(logThrowable.getMessage());
throwable.setStackTrace(logThrowable.getStackTraces());
throwable.initCause(setThrowable(logThrowable.getCause()));
return throwable;
}
示例4: LogEventConverter
import org.apache.twill.api.logging.LogThrowable; //导入依赖的package包/类
private LogEventConverter(String hostname, String runnableName) {
gson = new GsonBuilder()
.registerTypeAdapter(StackTraceElement.class, new StackTraceElementCodec())
.registerTypeAdapter(LogThrowable.class, new LogThrowableCodec())
.registerTypeAdapter(ILoggingEvent.class, new ILoggingEventSerializer(hostname, runnableName))
.create();
}
示例5: serialize
import org.apache.twill.api.logging.LogThrowable; //导入依赖的package包/类
@Override
public JsonElement serialize(LogThrowable throwable, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();
json.addProperty("className", throwable.getClassName());
json.addProperty("message", throwable.getMessage());
json.add("stackTraces", context.serialize(throwable.getStackTraces(), StackTraceElement[].class));
LogThrowable cause = throwable.getCause();
if (cause != null) {
json.add("cause", context.serialize(cause, LogThrowable.class));
}
return json;
}
示例6: testLogHandler
import org.apache.twill.api.logging.LogThrowable; //导入依赖的package包/类
@Test
public void testLogHandler() throws ExecutionException, InterruptedException, TimeoutException {
final CountDownLatch latch = new CountDownLatch(3);
final Queue<LogThrowable> throwables = new ConcurrentLinkedQueue<LogThrowable>();
final Queue<String> runnables = new ConcurrentLinkedQueue<String>();
LogHandler logHandler = new LogHandler() {
@Override
public void onLog(LogEntry logEntry) {
// Would expect logs from AM and the runnable.
if (logEntry.getSourceClassName().contains("LogHandlerTestRun")) {
runnables.add(logEntry.getRunnableName());
}
// Runnable name for AM should be null
if (logEntry.getSourceClassName().contains("ApplicationMasterService")) {
Assert.assertNull(logEntry.getRunnableName());
}
if (logEntry.getMessage().startsWith("Starting runnable " + LogRunnable.class.getSimpleName())) {
latch.countDown();
} else if (logEntry.getMessage().equals("Running")) {
latch.countDown();
} else if (logEntry.getMessage().equals("Got exception") && logEntry.getThrowable() != null) {
throwables.add(logEntry.getThrowable());
latch.countDown();
}
}
};
TwillRunner runner = getTwillRunner();
TwillController controller = runner.prepare(new LogRunnable())
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
.addLogHandler(logHandler)
.start();
try {
Assert.assertTrue(latch.await(100, TimeUnit.SECONDS));
} finally {
controller.terminate().get(120, TimeUnit.SECONDS);
}
// Verify the runnable names
Assert.assertEquals(2, runnables.size());
Assert.assertArrayEquals(new String[] {"LogRunnable", "LogRunnable"}, runnables.toArray());
// Verify the log throwable
Assert.assertEquals(1, throwables.size());
LogThrowable t = throwables.poll();
Assert.assertEquals(RuntimeException.class.getName(), t.getClassName());
Assert.assertNotNull(t.getCause());
Assert.assertEquals(5, t.getStackTraces().length);
t = t.getCause();
Assert.assertEquals(Exception.class.getName(), t.getClassName());
Assert.assertEquals("Exception", t.getMessage());
}
示例7: getCause
import org.apache.twill.api.logging.LogThrowable; //导入依赖的package包/类
@Override
public LogThrowable getCause() {
return cause;
}
示例8: deserialize
import org.apache.twill.api.logging.LogThrowable; //导入依赖的package包/类
@Override
public LogThrowable deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
return context.deserialize(json, DefaultLogThrowable.class);
}
示例9: testLogHandler
import org.apache.twill.api.logging.LogThrowable; //导入依赖的package包/类
@Test
public void testLogHandler() throws ExecutionException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(3);
final Queue<LogThrowable> throwables = new ConcurrentLinkedQueue<LogThrowable>();
final Queue<String> runnables = new ConcurrentLinkedQueue<String>();
LogHandler logHandler = new LogHandler() {
@Override
public void onLog(LogEntry logEntry) {
// Would expect logs from AM and the runnable.
if (logEntry.getSourceClassName().contains("LogHandlerTestRun")) {
runnables.add(logEntry.getRunnableName());
}
// Runnable name for AM should be null
if (logEntry.getSourceClassName().contains("ApplicationMasterService")) {
Assert.assertNull(logEntry.getRunnableName());
}
if (logEntry.getMessage().startsWith("Starting runnable " + LogRunnable.class.getSimpleName())) {
latch.countDown();
} else if (logEntry.getMessage().equals("Running")) {
latch.countDown();
} else if (logEntry.getMessage().equals("Got exception") && logEntry.getThrowable() != null) {
throwables.add(logEntry.getThrowable());
latch.countDown();
}
}
};
TwillRunner runner = YarnTestUtils.getTwillRunner();
TwillController controller = runner.prepare(new LogRunnable())
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
.addLogHandler(logHandler)
.start();
try {
Assert.assertTrue(latch.await(100, TimeUnit.SECONDS));
} finally {
controller.stopAndWait();
}
// Verify the runnable names
Assert.assertEquals(2, runnables.size());
Assert.assertArrayEquals(new String[] {"LogRunnable", "LogRunnable"}, runnables.toArray());
// Verify the log throwable
Assert.assertEquals(1, throwables.size());
LogThrowable t = throwables.poll();
Assert.assertEquals(RuntimeException.class.getName(), t.getClassName());
Assert.assertNotNull(t.getCause());
Assert.assertEquals(5, t.getStackTraces().length);
t = t.getCause();
Assert.assertEquals(Exception.class.getName(), t.getClassName());
Assert.assertEquals("Exception", t.getMessage());
}