reactor.util.Logger类的使用及代码示例

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

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

Logger介绍

[英]Logger interface designed for internal Reactor usage.
[中]记录器接口设计用于内部反应堆使用。

代码示例

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

@Override
@Nullable
public Consumer<? super Throwable> onErrorCall() {
  boolean shouldLogAsDebug = level == Level.FINE && log.isDebugEnabled();
  boolean shouldLogAsTrace = level == Level.FINEST && log.isTraceEnabled();
  boolean shouldLogAsError = level != Level.FINE && level != Level.FINEST && log.isErrorEnabled();
  if ((options & ON_ERROR) == ON_ERROR && (shouldLogAsError || shouldLogAsDebug ||
      shouldLogAsTrace)) {
    if (shouldLogAsTrace) {
      return e -> {
        log.trace(s, SignalType.ON_ERROR, e, source);
        log.trace("", e);
      };
        log.debug(s, SignalType.ON_ERROR, e, source);
        log.debug("", e);
      };
        log.error(s, SignalType.ON_ERROR, e, source);
        log.error("", e);
      };

代码示例来源: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

@Override
public boolean isInfoEnabled() {
  return delegate.isInfoEnabled();
}

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

/**
 * Reset the {@link #onHandleError(BiConsumer)} hook to the default no-op behavior.
 */
public static void resetOnHandleError() {
  if (log.isDebugEnabled()) {
    log.debug("Reset to factory defaults: onHandleError");
  }
  onHandleErrorHook = null;
}

代码示例来源:origin: spring-cloud/spring-cloud-sleuth

@Override
public void onSubscribe(Subscription subscription) {
  if (log.isTraceEnabled()) {
    log.trace("On subscribe");
  }
  this.s = subscription;
  try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(this.span)) {
    if (log.isTraceEnabled()) {
      log.trace("On subscribe - span continued");
    }
    this.subscriber.onSubscribe(this);
  }
}

代码示例来源: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

@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

@Test
public void logErrorUsesDebugWhenFine() {
  Level level = Level.FINE;
  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, never()).isErrorEnabled();
  verify(mockLogger, times(1)).isDebugEnabled();
  verify(mockLogger, never()).isTraceEnabled();
  verify(mockLogger, times(1)).debug(Mockito.anyString(), (Object[]) Mockito.any());
  verify(mockLogger, times(1)).debug(Mockito.anyString(), (Throwable) Mockito.any());
  verifyNoMoreInteractions(mockLogger);
}

代码示例来源:origin: io.projectreactor.ipc/reactor-netty

@Override
public void fireContextError(Throwable err) {
  if (AbortedException.isConnectionReset(err)) {
    if (log.isDebugEnabled()) {
      log.debug("Connection closed remotely", err);
    }
  }
  else if (log.isErrorEnabled()) {
    log.error("Handler failure while no child channelOperation was present", err);
  }
}

代码示例来源:origin: io.projectreactor.ipc/reactor-ipc

final boolean receive(long streamId,
    StreamContext<?> ctx,
    StreamOperationsImpl io) {
  Publisher<?> p = producer(streamId, io);
  try {
    m.invoke(instance, ctx, p);
  }
  catch (Throwable ex) {
    if (log.isErrorEnabled()) {
      log.error("", ex);
    }
    io.sendCancel(streamId, ex.toString());
  }
  return true;
}

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

public void run() {
  LOGGER.debug("expired {}", state);
  @SuppressWarnings("unchecked")
  Signal<T> emptyState = (Signal<T>) EMPTY;
  state = emptyState;
}

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

@Test
public void logErrorUsesTraceWhenFinest() {
  Level level = Level.FINEST;
  demonstrateLogError(); //added to the test suite so that sanity check can be done
  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, never()).isErrorEnabled();
  verify(mockLogger, never()).isDebugEnabled();
  verify(mockLogger, times(1)).isTraceEnabled();
  verify(mockLogger, times(1)).trace(Mockito.anyString(), (Object[]) Mockito.any());
  verify(mockLogger, times(1)).trace(Mockito.anyString(), (Throwable) Mockito.any());
  verifyNoMoreInteractions(mockLogger);
}

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

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

代码示例来源: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);
}

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

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

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

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

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

void log() {
    if (log.isInfoEnabled()) {
      log.info(COMMON_LOG_FORMAT, address, user, zonedDateTime,
          method, uri, protocol, status, (contentLength > -1 ? contentLength : MISSING), port, duration());
    }
  }
}

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

@Override
public boolean isDebugEnabled() {
  return delegate.isDebugEnabled();
}

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

@Test
public void isTraceEnabled() throws Exception {
  assertThat(logger.isTraceEnabled()).isTrue();
}

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

@Override
public boolean isErrorEnabled() {
  return delegate.isErrorEnabled();
}

相关文章