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

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

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

Logger.isDebugEnabled介绍

[英]Is the logger instance enabled for the DEBUG level?
[中]是否为调试级别启用了记录器实例?

代码示例

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

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

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

/**
 * Define a hook that is executed when a {@link Scheduler} has
 * {@link #handleError(Throwable) handled an error}. Note that it is executed after
 * the error has been passed to the thread uncaughtErrorHandler, which is not the
 * case when a fatal error occurs (see {@link Exceptions#throwIfJvmFatal(Throwable)}).
 *
 * @param c the new hook to set.
 */
public static void onHandleError(BiConsumer<Thread, ? super Throwable> c) {
  if (log.isDebugEnabled()) {
    log.debug("Hooking new default: onHandleError");
  }
  onHandleErrorHook = Objects.requireNonNull(c, "onHandleError");
}

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

/**
 * Log an {@link IllegalStateException} that indicates more than the requested
 * amount was produced.
 *
 * @see Exceptions#failWithOverflow()
 */
public static void reportMoreProduced() {
  if (log.isDebugEnabled()) {
    log.debug("More data produced than requested",
        Exceptions.failWithOverflow());
  }
}

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

/**
 * Log a {@link Exceptions#duplicateOnSubscribeException() duplicate subscription} error.
 *
 * @see Exceptions#duplicateOnSubscribeException()
 */
public static void reportSubscriptionSet() {
  if (log.isDebugEnabled()) {
    log.debug("Duplicate Subscription has been detected",
        Exceptions.duplicateOnSubscribeException());
  }
}

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

/**
 * Log an {@link IllegalArgumentException} if the request is null or negative.
 *
 * @param n the failing demand
 *
 * @see Exceptions#nullOrNegativeRequestException(long)
 */
public static void reportBadRequest(long n) {
  if (log.isDebugEnabled()) {
    log.debug("Negative request",
        Exceptions.nullOrNegativeRequestException(n));
  }
}

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

/**
 * An unexpected event is about to be dropped.
 * <p>
 * If no hook is registered for {@link Hooks#onNextDropped(Consumer)}, the dropped
 * element is just logged at DEBUG level.
 *
 * @param <T> the dropped value type
 * @param t the dropped data
 * @param context a context that might hold a local next consumer
 */
public static <T> void onNextDropped(T t, Context context) {
  Objects.requireNonNull(t, "onNext");
  Objects.requireNonNull(context, "context");
  Consumer<Object> hook = context.getOrDefault(Hooks.KEY_ON_NEXT_DROPPED, null);
  if (hook == null) {
    hook = Hooks.onNextDroppedHook;
  }
  if (hook != null) {
    hook.accept(t);
  }
  else if (log.isDebugEnabled()) {
    log.debug("onNextDropped: " + t);
  }
}

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

/**
 * Structured logging with level adaptation and operator ascii graph if required +
 * protection against loggers that detect objects like {@link Fuseable.QueueSubscription}
 * as {@link java.util.Collection} and attempt to use their iterator for logging.
 *
 * @see #log
 */
void safeLog(SignalType signalType, Object signalValue) {
  try {
    log(signalType, signalValue);
  }
  catch (UnsupportedOperationException uoe) {
    log(signalType, String.valueOf(signalValue));
    if (log.isDebugEnabled()) {
      log.debug("UnsupportedOperationException has been raised by the logging framework, does your log() placement make sense? " +
          "eg. 'window(2).log()' instead of 'window(2).flatMap(w -> w.log())'", uoe);
    }
  }
}

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

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

代码示例来源: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 debugDismissedInNonVerboseMode() {
  Logger log = new Loggers.ConsoleLogger("test", new PrintStream(outContent), new PrintStream(errContent), false);
  log.debug("foo");
  log.debug("foo", new IllegalArgumentException("foo"));
  log.debug("foo {}", "foo");
  assertThat(outContent.toString()).doesNotContain("foo");
  assertThat(errContent.toString()).doesNotContain("foo");
  assertThat(log.isDebugEnabled()).as("isDebugEnabled").isFalse();
}

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

void evict(@Nullable T evicted) {
  if (evicted != null) {
    try {
      onBufferEviction.accept(evicted);
    }
    catch (Throwable ex) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(
            "value [{}] couldn't be evicted due to a callback error. This error will be dropped: {}",
            evicted,
            ex);
      }
      Operators.onErrorDropped(ex, actual.currentContext());
    }
    Operators.onDiscard(evicted, actual.currentContext());
  }
}

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

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

@Override
protected void initChannel(Channel ch) {
  if (pipeline != null) {
    for (PipelineConfiguration pipelineConfiguration : pipeline) {
      pipelineConfiguration.consumer.accept(listener, ch);
    }
  }
  ChannelOperations.addReactiveBridge(ch, opsFactory, listener);
  if (log.isDebugEnabled()) {
    log.debug(format(ch, "Initialized pipeline {}"), ch.pipeline().toString());
  }
}

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

/**
 * Log a {@link Exceptions#duplicateOnSubscribeException() duplicate subscription} error.
 *
 * @see Exceptions#duplicateOnSubscribeException()
 */
public static void reportSubscriptionSet() {
  if (log.isDebugEnabled()) {
    log.debug("Duplicate Subscription has been detected",
        Exceptions.duplicateOnSubscribeException());
  }
}

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

@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) {
  if (log.isDebugEnabled()) {
    log.debug(format(ctx.channel(), "Write state change {}"),
        ctx.channel()
          .isWritable());
  }
  drain();
}

相关文章