org.slf4j.Logger#isWarnEnabled ( )源码实例Demo

下面列出了org.slf4j.Logger#isWarnEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Albianj2   文件: AlbianLoggerService.java
@Override
public <T extends Exception> void warnAndThrow(String loggerName,
                                               Class<T> cls, String eInfo, String format, Object... values)
        throws RuntimeException {
    Logger logger = getLogger(loggerName);
    if (null == logger)
        return;
    if (logger.isWarnEnabled()) {
        String id = AlbianServiceRouter.getLogIdService().makeLoggerId();
        String msg = getWarnMsg(format, values);
        String tMsg = String.format("%s | %s.", id, msg);
        logger.warn(tMsg);
        Class[] clss = new Class[]{String.class};
        Object[] vars = new Object[]{"Warn:" + id + "," + eInfo};
        T throwObject = null;
        try {
            throwObject = (T) AlbianReflect.newInstance(cls, clss, vars);
        } catch (Exception e1) {
            throw new RuntimeException(e1);
        }
        if (null != throwObject)
            throw new RuntimeException(throwObject);
    }
}
 
源代码2 项目: ratis   文件: JavaUtils.java
/** Attempt to wait the given condition to return true multiple times. */
static void attempt(
    BooleanSupplier condition, int numAttempts, TimeDuration sleepTime, String name, Logger log)
    throws InterruptedException {
  Objects.requireNonNull(condition, "condition == null");
  Preconditions.assertTrue(numAttempts > 0, () -> "numAttempts = " + numAttempts + " <= 0");
  Preconditions.assertTrue(!sleepTime.isNegative(), () -> "sleepTime = " + sleepTime + " < 0");

  for(int i = 1; i <= numAttempts; i++) {
    if (condition.getAsBoolean()) {
      return;
    }
    if (log != null && log.isWarnEnabled()) {
      log.warn("FAILED " + name + " attempt #" + i + "/" + numAttempts
          + ": sleep " + sleepTime + " and then retry.");
    }

    sleepTime.sleep();
  }

  if (!condition.getAsBoolean()) {
    throw new IllegalStateException("Failed " + name + " for " + numAttempts + " attempts.");
  }
}
 
源代码3 项目: ratis   文件: LogUtils.java
static <OUTPUT, THROWABLE extends Throwable> OUTPUT supplyAndLog(
    Logger log, CheckedSupplier<OUTPUT, THROWABLE> supplier, Supplier<String> name)
    throws THROWABLE {
  final OUTPUT output;
  try {
    output = supplier.get();
  } catch (Throwable t) {
    if (log.isTraceEnabled()) {
      log.trace("Failed to " + name.get(), t);
    } else if (log.isWarnEnabled()){
      log.warn("Failed to " + name.get() + ": " + t);
    }
    final THROWABLE throwable = JavaUtils.cast(t);
    throw throwable;
  }

  if (log.isTraceEnabled()) {
    log.trace("Successfully supplied " + name.get() + ": " + output);
  }
  return output;
}
 
源代码4 项目: gemfirexd-oss   文件: EventErrorLogger.java
/**
 * If there is an existing file with given path, then try to roll it over with
 * a suffix like -01-01 in the name. If rolling fails for some reason then log
 * a warning and try to use rolled over file name.
 */
public String rollFileIfRequired(String logfile, Logger logger) {
  final File logFile = new File(logfile);
  if (logFile.exists()) {
    final File oldMain = ManagerLogWriter.getLogNameForOldMainLog(logFile,
        false);
    if (!logFile.renameTo(oldMain)) {
      logfile = oldMain.getPath();
      if (logger.isWarnEnabled()) {
        logger.info(Gfxd_EVENT_ERROR_LOGGER, logFile, oldMain);
      }
    }
    else {
      logfile = logFile.getPath();
    }
  }
  return logfile;
}
 
源代码5 项目: gemfirexd-oss   文件: SectDBSynchronizer.java
/**
 * If there is an existing file with given path, then try to roll it over with
 * a suffix like -01-01 in the name. If rolling fails for some reason then log
 * a warning and try to use rolled over file name.
 */
public String rollFileIfRequired(String logfile, Logger logger) {
  final File logFile = new File(logfile);
  if (logFile.exists()) {
    final File oldMain = ManagerLogWriter.getLogNameForOldMainLog(logFile,
        false);
    if (!logFile.renameTo(oldMain)) {
      logfile = oldMain.getPath();
      if (logger.isWarnEnabled()) {
        logger.info(Gfxd_DB_SYNCHRONIZER_16, logFile, oldMain);
      }
    }
    else {
      logfile = logFile.getPath();
    }
  }
  return logfile;
}
 
源代码6 项目: xipki   文件: LogUtil.java
public static void warn(Logger log, Throwable th, String msg) {
  if (!log.isWarnEnabled()) {
    return;
  }

  // this operation is expensive, hence don't abuse it.
  StackTraceElement[] traces = Thread.currentThread().getStackTrace();
  if (traces.length > 2) {
    StackTraceElement trace = traces[2];
    log.warn("({} {}) {}, {}: {}", trace.getMethodName(), trace.getLineNumber(), msg,
        th.getClass().getName(), th.getMessage());
  } else {
    log.warn("{}, {}: {}", msg, th.getClass().getName(), th.getMessage());
  }
  if (th instanceof RuntimeException) {
    log.warn(msg, th);
  } else {
    log.debug(msg, th);
  }
}
 
源代码7 项目: incubator-ratis   文件: LogUtils.java
static <THROWABLE extends Throwable> void runAndLog(
    Logger log, CheckedRunnable<THROWABLE> op, Supplier<String> opName)
    throws THROWABLE {
  try {
    op.run();
  } catch (Throwable t) {
    if (log.isTraceEnabled()) {
      log.trace("Failed to " + opName.get(), t);
    } else if (log.isWarnEnabled()){
      log.warn("Failed to " + opName.get() + ": " + t);
    }
    throw t;
  }

  if (log.isTraceEnabled()) {
    log.trace("Successfully ran " + opName.get());
  }
}
 
源代码8 项目: incubator-ratis   文件: LogUtils.java
static <OUTPUT, THROWABLE extends Throwable> OUTPUT supplyAndLog(
    Logger log, CheckedSupplier<OUTPUT, THROWABLE> supplier, Supplier<String> name)
    throws THROWABLE {
  final OUTPUT output;
  try {
    output = supplier.get();
  } catch (Throwable t) {
    if (log.isTraceEnabled()) {
      log.trace("Failed to " + name.get(), t);
    } else if (log.isWarnEnabled()){
      log.warn("Failed to " + name.get() + ": " + t);
    }
    final THROWABLE throwable = JavaUtils.cast(t);
    throw throwable;
  }

  if (log.isTraceEnabled()) {
    log.trace("Successfully supplied " + name.get() + ": " + output);
  }
  return output;
}
 
源代码9 项目: pinpoint   文件: LoggerUtils.java
public static int getLoggerLevel(Logger logger) {
    if (logger == null) {
        throw new NullPointerException("logger");
    }
    if (logger.isTraceEnabled()) {
        return TRACE_LEVEL;
    }
    if (logger.isDebugEnabled()) {
        return DEBUG_LEVEL;
    }
    if (logger.isInfoEnabled()) {
        return INFO_LEVEL;
    }
    if (logger.isWarnEnabled()) {
        return WARN_LEVEL;
    }
    if (logger.isErrorEnabled()) {
        return ERROR_LEVEL;
    }
    return DISABLE_LEVEL;
}
 
源代码10 项目: javalite   文件: LogFilter.java
private static boolean matches(Logger logger, LogLevel logLevel, String log)
{
    boolean isEnabled = true;

    switch (logLevel)
    {
    case DEBUG:
        isEnabled = logger.isDebugEnabled();
        break;
    case INFO:
        isEnabled = logger.isInfoEnabled();
        break;
    case WARNING:
        isEnabled = logger.isWarnEnabled();
        break;
    case ERROR:
        isEnabled = logger.isErrorEnabled();
        break;
    default:
    }
    return isEnabled && pattern.matcher(log).matches();
}
 
源代码11 项目: gemfirexd-oss   文件: SectDBSynchronizer.java
/**
 * If there is an existing file with given path, then try to roll it over with
 * a suffix like -01-01 in the name. If rolling fails for some reason then log
 * a warning and try to use rolled over file name.
 */
public String rollFileIfRequired(String logfile, Logger logger) {
  final File logFile = new File(logfile);
  if (logFile.exists()) {
    final File oldMain = ManagerLogWriter.getLogNameForOldMainLog(logFile,
        false);
    if (!logFile.renameTo(oldMain)) {
      logfile = oldMain.getPath();
      if (logger.isWarnEnabled()) {
        logger.info(Gfxd_DB_SYNCHRONIZER_16, logFile, oldMain);
      }
    }
    else {
      logfile = logFile.getPath();
    }
  }
  return logfile;
}
 
源代码12 项目: armeria   文件: Exceptions.java
/**
 * Logs the specified exception if it is {@linkplain #isExpected(Throwable) unexpected}.
 */
public static void logIfUnexpected(Logger logger, Channel ch, String debugData, Throwable cause) {

    if (!logger.isWarnEnabled() || isExpected(cause)) {
        return;
    }

    logger.warn("{} Unexpected exception: {}", ch, debugData, cause);
}
 
源代码13 项目: armeria   文件: DnsUtil.java
/**
 * Logs a warning message about an invalid record.
 */
public static void warnInvalidRecord(Logger logger, String logPrefix, DnsRecordType type, ByteBuf content) {
    if (logger.isWarnEnabled()) {
        final String dump = ByteBufUtil.hexDump(content);
        logger.warn("{} Skipping invalid {} record: {}",
                    logPrefix, type.name(), dump.isEmpty() ? "<empty>" : dump);
    }
}
 
源代码14 项目: uncode-dal-all   文件: WriterTask.java
private void flush() {
    Logger logWriter = config.getLog();
    if (logWriter == null)
        logWriter = LOGGER;

    for (T r : records) {
        if (logWriter.isWarnEnabled()) {
            logWriter.info(String.valueOf(r));
        }
    }

    records.clear();
    timestamp = System.currentTimeMillis();
}
 
源代码15 项目: ph-commons   文件: ServiceLoaderHelper.java
/**
 * Uses the {@link ServiceLoader} to load all SPI implementations of the
 * passed class and return only the first instance.
 *
 * @param <T>
 *        The implementation type to be loaded
 * @param aSPIClass
 *        The SPI interface class. May not be <code>null</code>.
 * @param aClassLoader
 *        The class loader to use for the SPI loader. May not be
 *        <code>null</code>.
 * @param aLogger
 *        An optional logger to use. May be <code>null</code>.
 * @return A collection of all currently available plugins. Never
 *         <code>null</code>.
 */
@Nullable
public static <T> T getFirstSPIImplementation (@Nonnull final Class <T> aSPIClass,
                                               @Nonnull final ClassLoader aClassLoader,
                                               @Nullable final Logger aLogger)
{
  final Logger aRealLogger = aLogger != null ? aLogger : LOGGER;
  final ICommonsList <T> aAll = getAllSPIImplementations (aSPIClass, aClassLoader, aRealLogger);
  if (aAll.isEmpty ())
  {
    // No SPI implementation found
    return null;
  }

  if (aAll.size () > 1)
  {
    // More than one implementation found
    if (aRealLogger.isWarnEnabled ())
      aRealLogger.warn ("Requested only one SPI implementation of " +
                        aSPIClass +
                        " but found " +
                        aAll.size () +
                        " - using the first one. Details: " +
                        aAll);
  }
  return aAll.getFirst ();
}
 
源代码16 项目: arcusplatform   文件: ReflexLogNoMessageContext.java
@Override
public void run(DeviceDriverContext context, Object value) {
   Logger log = context.getLogger();

   switch (lg.getLevel()) {
   case TRACE:
      if (log.isTraceEnabled()) {
         log.trace(message());
      }
      break;

   case DEBUG:
      if (log.isDebugEnabled()) {
         log.debug(message());
      }
      break;

   case INFO:
      if (log.isInfoEnabled()) {
         log.info(message());
      }
      break;

   case WARN:
      if (log.isWarnEnabled()) {
         log.warn(message());
      }
      break;

   case ERROR:
      if (log.isErrorEnabled()) {
         log.error(message());
      }
      break;

   default:
      if (log.isDebugEnabled()) {
         log.debug(message());
      }
      break;
   }
}
 
源代码17 项目: Raincat   文件: LogUtil.java
public static void warn(Logger logger, String format, Supplier<Object> supplier) {
    if (logger.isWarnEnabled()) {
        logger.warn(format, supplier.get());
    }
}
 
源代码18 项目: qpid-broker-j   文件: Slf4jLoggingHandler.java
@Override
public boolean isEnabled(final Logger logger)
{
    return logger.isWarnEnabled();
}
 
源代码19 项目: secure-data-service   文件: LogUtil.java
/**
 * Write the appropriate warning message to the log file
 *
 * @param log
 *            logger to write the message
 * @param message
 *            specific message to write to the log file
 * @param exception
 *            the exception which caused the log file entry
 */
public static void warn(Logger log, String message, Throwable exception) {
    // Log the error with a message-safe exception.
    if (log.isWarnEnabled()) {
        Throwable loggingException = createLoggingException(exception);
        log.warn(message, loggingException);
    }
}
 
源代码20 项目: myth   文件: LogUtil.java
/**
 * Warn.
 *
 * @param logger   the logger
 * @param format   the format
 * @param supplier the supplier
 */
public static void warn(Logger logger, String format, Supplier<Object> supplier) {
    if (logger.isWarnEnabled()) {
        logger.warn(format, supplier.get());
    }
}