当前位置: 首页>>代码示例>>Java>>正文


Java LogThrowable类代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:twill,代码行数:23,代码来源:ILoggingEventSerializer.java

示例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);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:28,代码来源:YarnTwillLogHandler.java

示例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;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:10,代码来源:YarnTwillLogHandler.java

示例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();
}
 
开发者ID:apache,项目名称:twill,代码行数:8,代码来源:KafkaAppender.java

示例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;
}
 
开发者ID:apache,项目名称:twill,代码行数:15,代码来源:LogThrowableCodec.java

示例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());
}
 
开发者ID:apache,项目名称:twill,代码行数:57,代码来源:LogHandlerTestRun.java

示例7: getCause

import org.apache.twill.api.logging.LogThrowable; //导入依赖的package包/类
@Override
public LogThrowable getCause() {
  return cause;
}
 
开发者ID:apache,项目名称:twill,代码行数:5,代码来源:DefaultLogThrowable.java

示例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);
}
 
开发者ID:apache,项目名称:twill,代码行数:6,代码来源:LogThrowableCodec.java

示例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());
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:57,代码来源:LogHandlerTestRun.java


注:本文中的org.apache.twill.api.logging.LogThrowable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。