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

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

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

Logger.isErrorEnabled介绍

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

代码示例

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

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

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

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

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

@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

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)) {

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

public static void invokeDone(Object api, StreamContext<?> ctx) {
  for (Method m : api.getClass()
            .getMethods()) {
    if (m.isAnnotationPresent(IpcDone.class)) {
      if (m.getReturnType() == Void.TYPE) {
        if (m.getParameterCount() == 1 && StreamContext.class.isAssignableFrom(
            m.getParameterTypes()[0])) {
          try {
            m.invoke(api, ctx);
          }
          catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            if (log.isErrorEnabled()) {
              log.error("", e);
            }
            throw new IllegalStateException(e);
          }
          return;
        }
      }
      throw new IllegalStateException(
          "IpcInit method has to be void and accepting only a single StreamContext parameter");
    }
  }
}

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

public static void invokeInit(Object api, StreamContext<?> ctx) {
  for (Method m : api.getClass()
            .getMethods()) {
    if (m.isAnnotationPresent(IpcInit.class)) {
      if (m.getReturnType() == Void.TYPE) {
        if (m.getParameterCount() == 1 && StreamContext.class.isAssignableFrom(
            m.getParameterTypes()[0])) {
          try {
            m.invoke(api, ctx);
          }
          catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            if (log.isErrorEnabled()) {
              log.error("", e);
            }
            throw new IllegalStateException(e);
          }
          return;
        }
      }
      throw new IllegalStateException(
          "IpcInit method has to be void and accepting only a single StreamContext parameter");
    }
  }
}

代码示例来源: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: io.projectreactor.ipc/reactor-ipc

public static boolean dispatchServer(long streamId,
    Object action,
    StreamOperationsImpl io,
    StreamContext<?> ctx) {
  if (action instanceof IpcServerSend) {
    IpcServerSend rpcServerSend = (IpcServerSend) action;
    return rpcServerSend.send(streamId, ctx, io);
  }
  else if (action instanceof IpcServerReceive) {
    IpcServerReceive rpcServerReceive = (IpcServerReceive) action;
    return rpcServerReceive.receive(streamId, ctx, io);
  }
  else if (action instanceof IpcServerMap) {
    IpcServerMap rpcServerMap = (IpcServerMap) action;
    return rpcServerMap.map(streamId, ctx, io);
  }
  if (log.isErrorEnabled()) {
    log.error("",
        new IllegalStateException("Unsupported action: " + action.getClass()));
  }
  return false;
}

代码示例来源: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 map(long streamId, StreamContext<?> ctx, StreamOperationsImpl io) {
  AtomicInteger innerOnce = new AtomicInteger(2);
  ServerSendSubscriber sender =
      new ServerSendSubscriber(streamId, io, innerOnce);
  Publisher<?> p = producer(streamId, innerOnce, sender, io);
  Publisher<?> u;
  try {
    u = (Publisher<?>) m.invoke(instance, ctx, p);
  }
  catch (Throwable ex) {
    if (log.isErrorEnabled()) {
      log.error("", ex);
    }
    u = s -> Operators.error(s, ex);
  }
  if (u == null) {
    u = s -> Operators.error(s,
        new NullPointerException(
            "The service implementation returned a null Publisher"));
  }
  u.subscribe(sender);
  return true;
}

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

@Override
protected IN decodeNext(Buffer buffer, Object context) {
  try {
    Class<IN> clazz = readType(buffer);
    byte[] bytes = buffer.asBytes();
    buffer.position(buffer.limit());
    return deserializer(engine, clazz).apply(bytes);
  } catch (RuntimeException e) {
    if (log.isErrorEnabled()) {
      log.error("Could not decode " + buffer, e);
    }
    throw e;
  }
}

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

public boolean send(long streamId, StreamContext<?> ctx, StreamOperationsImpl io) {
  Publisher<?> output;
  try {
    output = (Publisher<?>) m.invoke(instance, ctx);
  }
  catch (Throwable ex) {
    if (log.isErrorEnabled()) {
      log.error("", ex);
    }
    io.sendError(streamId, ex);
    return true;
  }
  if (output == null) {
    io.sendError(streamId,
        new IllegalStateException(
            "The service implementation returned a null Publisher"));
    return true;
  }
  ServerSendSubscriber parent = new ServerSendSubscriber(streamId, io);
  io.registerSubscription(streamId, parent);
  output.subscribe(parent);
  return true;
}

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

if (log.isErrorEnabled()) {
  log.error(format(channel, "Error while binding ChannelOperation on " + channel.pipeline()),
      t);

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

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)) {

相关文章