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

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

本文整理了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

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

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

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

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

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

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

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

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

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

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

@Override
  public void error(String msg, Throwable t) {
    delegate.error(msg, t);
  }
}

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

@Override
public void error(String msg) {
  delegate.error(msg);
}

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

static void handleError(Throwable ex) {
  Thread thread = Thread.currentThread();
  Throwable t = unwrap(ex);
  Thread.UncaughtExceptionHandler x = thread.getUncaughtExceptionHandler();
  if (x != null) {
    x.uncaughtException(thread, t);
  }
  else {
    log.error("Scheduler worker failed with an uncaught exception", t);
  }
  if (onHandleErrorHook != null) {
    onHandleErrorHook.accept(thread, t);
  }
}

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

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

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

/**
 * An unexpected exception is about to be dropped.
 * <p>
 * If no hook is registered for {@link Hooks#onErrorDropped(Consumer)}, the dropped
 * error is logged at ERROR level and thrown (via {@link Exceptions#bubble(Throwable)}.
 *
 * @param e the dropped exception
 * @param context a context that might hold a local error consumer
 */
public static void onErrorDropped(Throwable e, Context context) {
  Consumer<? super Throwable> hook = context.getOrDefault(Hooks.KEY_ON_ERROR_DROPPED,null);
  if (hook == null) {
    hook = Hooks.onErrorDroppedHook;
  }
  if (hook == null) {
    log.error("Operator called default onErrorDropped", e);
    throw Exceptions.bubble(e);
  }
  hook.accept(e);
}

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

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

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

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

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

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

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

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

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

@Test
public void errorNulls() {
  logger.error("vararg {} is {}", (Object[]) null);
  logger.error("param {} is {}", null, null);
  assertThat(errContent.toString())
      .contains("vararg {} is {}")
      .contains("param null is null");
  assertThat(outContent.size()).isZero();
}

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

@Test
public void logErrorUsesErrorWhenSevere() {
  Level level = Level.SEVERE;
  Mono<String> source = Mono.error(new IllegalStateException("ignored"));
  Logger mockLogger = Mockito.mock(Logger.class);
  when(mockLogger.isErrorEnabled()).thenReturn(true);
  when(mockLogger.isDebugEnabled()).thenReturn(true);
  when(mockLogger.isTraceEnabled()).thenReturn(true);
  SignalLogger<String> sl = new SignalLogger<>(source, null, level,
      false, s -> mockLogger);
  sl.onErrorCall().accept(new IllegalStateException("boom"));
  verify(mockLogger, times(1)).isErrorEnabled();
  verify(mockLogger, never()).isDebugEnabled();
  verify(mockLogger, never()).isTraceEnabled();
  verify(mockLogger, times(1)).error(Mockito.anyString(), (Object[]) Mockito.any());
  verify(mockLogger, times(1)).error(Mockito.anyString(), (Throwable) Mockito.any());
  verifyNoMoreInteractions(mockLogger);
}

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

@Test
public void logErrorUsesErrorWhenInfo() {
  Level level = Level.INFO;
  Mono<String> source = Mono.error(new IllegalStateException("ignored"));
  Logger mockLogger = Mockito.mock(Logger.class);
  when(mockLogger.isErrorEnabled()).thenReturn(true);
  when(mockLogger.isDebugEnabled()).thenReturn(true);
  when(mockLogger.isTraceEnabled()).thenReturn(true);
  SignalLogger<String> sl = new SignalLogger<>(source, null, level,
      false, s -> mockLogger);
  sl.onErrorCall().accept(new IllegalStateException("boom"));
  verify(mockLogger, times(1)).isErrorEnabled();
  verify(mockLogger, never()).isDebugEnabled();
  verify(mockLogger, never()).isTraceEnabled();
  verify(mockLogger, times(1)).error(Mockito.anyString(), (Object[]) Mockito.any());
  verify(mockLogger, times(1)).error(Mockito.anyString(), (Throwable) Mockito.any());
  verifyNoMoreInteractions(mockLogger);
}

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

@Test
public void logErrorUsesErrorWhenWarning() {
  Level level = Level.WARNING;
  Mono<String> source = Mono.error(new IllegalStateException("ignored"));
  Logger mockLogger = Mockito.mock(Logger.class);
  when(mockLogger.isErrorEnabled()).thenReturn(true);
  when(mockLogger.isDebugEnabled()).thenReturn(true);
  when(mockLogger.isTraceEnabled()).thenReturn(true);
  SignalLogger<String> sl = new SignalLogger<>(source, null, level,
      false, s -> mockLogger);
  sl.onErrorCall().accept(new IllegalStateException("boom"));
  verify(mockLogger, times(1)).isErrorEnabled();
  verify(mockLogger, never()).isDebugEnabled();
  verify(mockLogger, never()).isTraceEnabled();
  verify(mockLogger, times(1)).error(Mockito.anyString(), (Object[]) Mockito.any());
  verify(mockLogger, times(1)).error(Mockito.anyString(), (Throwable) Mockito.any());
  verifyNoMoreInteractions(mockLogger);
}

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

/**
 * Structured logging with level adaptation and operator ascii graph if required.
 *
 * @param signalType the type of signal being logged
 * @param signalValue the value for the signal (use empty string if not required)
 */
void log(SignalType signalType, Object signalValue) {
  String line = fuseable ? LOG_TEMPLATE_FUSEABLE : LOG_TEMPLATE;
  if (operatorLine != null) {
    line = line + " " + operatorLine;
  }
  if (level == Level.FINEST) {
    log.trace(line, signalType, signalValue);
  }
  else if (level == Level.FINE) {
    log.debug(line, signalType, signalValue);
  }
  else if (level == Level.INFO) {
    log.info(line, signalType, signalValue);
  }
  else if (level == Level.WARNING) {
    log.warn(line, signalType, signalValue);
  }
  else if (level == Level.SEVERE) {
    log.error(line, signalType, signalValue);
  }
}

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

@Test
public void sampleTest() throws Exception {
  CountDownLatch latch = new CountDownLatch(1);
  Disposable top10every1second =
   Flux.fromIterable(PULP_SAMPLE)
       .publishOn(asyncGroup)
       .flatMap(samuelJackson ->
      Flux
       .fromArray(samuelJackson.split(" "))
       .publishOn(asyncGroup)
       .filter(w -> !w.trim().isEmpty())
       .doOnNext(i -> simulateLatency())
    )
       .window(Duration.ofSeconds(2))
       .flatMap(s -> s.groupBy(w -> w)
              .flatMap(w -> w.count().map(c -> Tuples.of(w.key(), c)))
              .collectSortedList((a, b) -> -a.getT2().compareTo(b.getT2()))
              .flatMapMany(Flux::fromIterable)
              .take(10)
              .doAfterTerminate(() -> LOG.info("------------------------ window terminated" +
             "----------------------"))
    )
       .subscribe(
     entry -> LOG.info(entry.getT1() + ": " + entry.getT2()),
     error -> LOG.error("", error),
          latch::countDown
    );
  awaitLatch(top10every1second, latch);
}

相关文章