reactor.util.Logger.error()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(221)

本文整理了Java中reactor.util.Logger.error()方法的一些代码示例,展示了Logger.error()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logger.error()方法的具体详情如下:
包路径:reactor.util.Logger
类名称:Logger
方法名:error

Logger.error介绍

[英]Log a message at the ERROR level.
[中]在错误级别记录消息。

代码示例

代码示例来源:origin: reactor/reactor-core

  1. @Override
  2. public void onSubscribe(Subscription s) {
  3. Throwable e = new IllegalStateException("onSubscribe should not be used");
  4. log.error("Unexpected call to Operators.emptySubscriber()", e);
  5. }

代码示例来源:origin: reactor/reactor-core

  1. @Override
  2. public void onError(Throwable t) {
  3. Throwable e = new IllegalStateException("onError should not be used", t);
  4. log.error("Unexpected call to Operators.emptySubscriber()", e);
  5. }

代码示例来源:origin: reactor/reactor-core

  1. @Override
  2. public void onComplete() {
  3. Throwable e = new IllegalStateException("onComplete should not be used");
  4. log.error("Unexpected call to Operators.emptySubscriber()", e);
  5. }
  6. };

代码示例来源:origin: reactor/reactor-core

  1. @Override
  2. public void onNext(Object o) {
  3. Throwable e = new IllegalStateException("onNext should not be used, got " + o);
  4. log.error("Unexpected call to Operators.emptySubscriber()", e);
  5. }

代码示例来源:origin: reactor/reactor-core

  1. static final void defaultUncaughtException(Thread t, Throwable e) {
  2. Schedulers.log.error("Scheduler worker in group " + t.getThreadGroup().getName()
  3. + " failed with an uncaught exception", e);
  4. }

代码示例来源:origin: reactor/reactor-core

  1. @Override
  2. public void error(String msg, Throwable t) {
  3. delegate.error(msg, t);
  4. }
  5. }

代码示例来源:origin: reactor/reactor-core

  1. @Override
  2. public void error(String msg) {
  3. delegate.error(msg);
  4. }

代码示例来源:origin: reactor/reactor-core

  1. static void handleError(Throwable ex) {
  2. Thread thread = Thread.currentThread();
  3. Throwable t = unwrap(ex);
  4. Thread.UncaughtExceptionHandler x = thread.getUncaughtExceptionHandler();
  5. if (x != null) {
  6. x.uncaughtException(thread, t);
  7. }
  8. else {
  9. log.error("Scheduler worker failed with an uncaught exception", t);
  10. }
  11. if (onHandleErrorHook != null) {
  12. onHandleErrorHook.accept(thread, t);
  13. }
  14. }

代码示例来源:origin: reactor/reactor-core

  1. @Override
  2. public void onError(Throwable throwable) {
  3. log.error(throwable.getMessage(), throwable);
  4. }

代码示例来源:origin: reactor/reactor-core

  1. /**
  2. * An unexpected exception is about to be dropped.
  3. * <p>
  4. * If no hook is registered for {@link Hooks#onErrorDropped(Consumer)}, the dropped
  5. * error is logged at ERROR level and thrown (via {@link Exceptions#bubble(Throwable)}.
  6. *
  7. * @param e the dropped exception
  8. * @param context a context that might hold a local error consumer
  9. */
  10. public static void onErrorDropped(Throwable e, Context context) {
  11. Consumer<? super Throwable> hook = context.getOrDefault(Hooks.KEY_ON_ERROR_DROPPED,null);
  12. if (hook == null) {
  13. hook = Hooks.onErrorDroppedHook;
  14. }
  15. if (hook == null) {
  16. log.error("Operator called default onErrorDropped", e);
  17. throw Exceptions.bubble(e);
  18. }
  19. hook.accept(e);
  20. }

代码示例来源:origin: reactor/reactor-core

  1. @Override
  2. public void error(String format, Object... arguments) {
  3. delegate.error(format, wrapArguments(arguments));
  4. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void error() throws Exception {
  3. logger.error("message");
  4. assertThat(outContent.size()).isZero();
  5. assertThat(errContent.toString()).isEqualTo("[ERROR] (" + Thread.currentThread().getName() + ") message\n");
  6. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void error1() throws Exception {
  3. logger.error("message {} {} format", "with", 1);
  4. assertThat(outContent.size()).isZero();
  5. assertThat(errContent.toString()).isEqualTo("[ERROR] (" + Thread.currentThread().getName() + ") message with 1 format\n");
  6. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void error2() throws Exception {
  3. logger.error("with cause", CAUSE);
  4. assertThat(outContent.size()).isZero();
  5. assertThat(errContent.toString())
  6. .startsWith("[ERROR] (" + Thread.currentThread().getName() + ") with cause - java.lang.IllegalStateException: cause" +
  7. "\njava.lang.IllegalStateException: cause\n" +
  8. "\tat reactor.util.ConsoleLoggerTest");
  9. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void errorNulls() {
  3. logger.error("vararg {} is {}", (Object[]) null);
  4. logger.error("param {} is {}", null, null);
  5. assertThat(errContent.toString())
  6. .contains("vararg {} is {}")
  7. .contains("param null is null");
  8. assertThat(outContent.size()).isZero();
  9. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void logErrorUsesErrorWhenSevere() {
  3. Level level = Level.SEVERE;
  4. Mono<String> source = Mono.error(new IllegalStateException("ignored"));
  5. Logger mockLogger = Mockito.mock(Logger.class);
  6. when(mockLogger.isErrorEnabled()).thenReturn(true);
  7. when(mockLogger.isDebugEnabled()).thenReturn(true);
  8. when(mockLogger.isTraceEnabled()).thenReturn(true);
  9. SignalLogger<String> sl = new SignalLogger<>(source, null, level,
  10. false, s -> mockLogger);
  11. sl.onErrorCall().accept(new IllegalStateException("boom"));
  12. verify(mockLogger, times(1)).isErrorEnabled();
  13. verify(mockLogger, never()).isDebugEnabled();
  14. verify(mockLogger, never()).isTraceEnabled();
  15. verify(mockLogger, times(1)).error(Mockito.anyString(), (Object[]) Mockito.any());
  16. verify(mockLogger, times(1)).error(Mockito.anyString(), (Throwable) Mockito.any());
  17. verifyNoMoreInteractions(mockLogger);
  18. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void logErrorUsesErrorWhenInfo() {
  3. Level level = Level.INFO;
  4. Mono<String> source = Mono.error(new IllegalStateException("ignored"));
  5. Logger mockLogger = Mockito.mock(Logger.class);
  6. when(mockLogger.isErrorEnabled()).thenReturn(true);
  7. when(mockLogger.isDebugEnabled()).thenReturn(true);
  8. when(mockLogger.isTraceEnabled()).thenReturn(true);
  9. SignalLogger<String> sl = new SignalLogger<>(source, null, level,
  10. false, s -> mockLogger);
  11. sl.onErrorCall().accept(new IllegalStateException("boom"));
  12. verify(mockLogger, times(1)).isErrorEnabled();
  13. verify(mockLogger, never()).isDebugEnabled();
  14. verify(mockLogger, never()).isTraceEnabled();
  15. verify(mockLogger, times(1)).error(Mockito.anyString(), (Object[]) Mockito.any());
  16. verify(mockLogger, times(1)).error(Mockito.anyString(), (Throwable) Mockito.any());
  17. verifyNoMoreInteractions(mockLogger);
  18. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void logErrorUsesErrorWhenWarning() {
  3. Level level = Level.WARNING;
  4. Mono<String> source = Mono.error(new IllegalStateException("ignored"));
  5. Logger mockLogger = Mockito.mock(Logger.class);
  6. when(mockLogger.isErrorEnabled()).thenReturn(true);
  7. when(mockLogger.isDebugEnabled()).thenReturn(true);
  8. when(mockLogger.isTraceEnabled()).thenReturn(true);
  9. SignalLogger<String> sl = new SignalLogger<>(source, null, level,
  10. false, s -> mockLogger);
  11. sl.onErrorCall().accept(new IllegalStateException("boom"));
  12. verify(mockLogger, times(1)).isErrorEnabled();
  13. verify(mockLogger, never()).isDebugEnabled();
  14. verify(mockLogger, never()).isTraceEnabled();
  15. verify(mockLogger, times(1)).error(Mockito.anyString(), (Object[]) Mockito.any());
  16. verify(mockLogger, times(1)).error(Mockito.anyString(), (Throwable) Mockito.any());
  17. verifyNoMoreInteractions(mockLogger);
  18. }

代码示例来源:origin: reactor/reactor-core

  1. /**
  2. * Structured logging with level adaptation and operator ascii graph if required.
  3. *
  4. * @param signalType the type of signal being logged
  5. * @param signalValue the value for the signal (use empty string if not required)
  6. */
  7. void log(SignalType signalType, Object signalValue) {
  8. String line = fuseable ? LOG_TEMPLATE_FUSEABLE : LOG_TEMPLATE;
  9. if (operatorLine != null) {
  10. line = line + " " + operatorLine;
  11. }
  12. if (level == Level.FINEST) {
  13. log.trace(line, signalType, signalValue);
  14. }
  15. else if (level == Level.FINE) {
  16. log.debug(line, signalType, signalValue);
  17. }
  18. else if (level == Level.INFO) {
  19. log.info(line, signalType, signalValue);
  20. }
  21. else if (level == Level.WARNING) {
  22. log.warn(line, signalType, signalValue);
  23. }
  24. else if (level == Level.SEVERE) {
  25. log.error(line, signalType, signalValue);
  26. }
  27. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void sampleTest() throws Exception {
  3. CountDownLatch latch = new CountDownLatch(1);
  4. Disposable top10every1second =
  5. Flux.fromIterable(PULP_SAMPLE)
  6. .publishOn(asyncGroup)
  7. .flatMap(samuelJackson ->
  8. Flux
  9. .fromArray(samuelJackson.split(" "))
  10. .publishOn(asyncGroup)
  11. .filter(w -> !w.trim().isEmpty())
  12. .doOnNext(i -> simulateLatency())
  13. )
  14. .window(Duration.ofSeconds(2))
  15. .flatMap(s -> s.groupBy(w -> w)
  16. .flatMap(w -> w.count().map(c -> Tuples.of(w.key(), c)))
  17. .collectSortedList((a, b) -> -a.getT2().compareTo(b.getT2()))
  18. .flatMapMany(Flux::fromIterable)
  19. .take(10)
  20. .doAfterTerminate(() -> LOG.info("------------------------ window terminated" +
  21. "----------------------"))
  22. )
  23. .subscribe(
  24. entry -> LOG.info(entry.getT1() + ": " + entry.getT2()),
  25. error -> LOG.error("", error),
  26. latch::countDown
  27. );
  28. awaitLatch(top10every1second, latch);
  29. }

相关文章