Java Code Examples for org.slf4j.Logger.isWarnEnabled()

The following are Jave code examples for showing how to use isWarnEnabled() of the org.slf4j.Logger class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: xitk   File: LogUtil.java   View Source Code Vote up 7 votes
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(), getMessage(th));
    } else {
        log.warn("{}, {}: {}", msg, th.getClass().getName(), getMessage(th));
    }
    log.debug(msg, th);
}
 
Example 2
Project: xitk   File: LogUtil.java   View Source Code Vote up 6 votes
public static void warn(Logger log, Throwable th) {
    if (!log.isWarnEnabled()) {
        return;
    }

    // this operation is expensive, don't abuse it.
    StackTraceElement[] traces = Thread.currentThread().getStackTrace();
    if (traces.length > 2) {
        StackTraceElement trace = traces[2];
        log.error("({} {}), {}: {}", trace.getMethodName(), trace.getLineNumber(),
                th.getClass().getName(), getMessage(th));
    } else {
        log.warn("{}: {}", th.getClass().getName(), getMessage(th));
    }
    log.debug("Exception", th);
}
 
Example 3
Project: incubator-ratis   File: LogUtils.java   View Source Code Vote up 6 votes
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());
  }
}
 
Example 4
Project: incubator-ratis   File: LogUtils.java   View Source Code Vote up 6 votes
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);
    }
    throw (THROWABLE)t;
  }

  if (log.isTraceEnabled()) {
    log.trace("Successfully supplied " + name.get());
  }
  return output;
}
 
Example 5
Project: incubator-ratis   File: JavaUtils.java   View Source Code Vote up 6 votes
/** Attempt to wait the given condition to return true multiple times. */
static void attempt(
    BooleanSupplier condition, int numAttempts, long sleepMs, String name, Logger log)
    throws InterruptedException {
  Objects.requireNonNull(condition, "condition == null");
  Preconditions.assertTrue(numAttempts > 0, () -> "numAttempts = " + numAttempts + " <= 0");
  Preconditions.assertTrue(sleepMs >= 0L, () -> "sleepMs = " + sleepMs + " < 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 " + sleepMs + "ms and then retry.");
    }
    if (sleepMs > 0) {
      Thread.sleep(sleepMs);
    }
  }

  if (!condition.getAsBoolean()) {
    throw new IllegalStateException("Failed " + name + " for " + numAttempts + " attempts.");
  }
}
 
Example 6
Project: easyhbase   File: LoggerUtils.java   View Source Code Vote up 6 votes
public static int getLoggerLevel(Logger logger) {
    if (logger == null) {
        throw new NullPointerException("logger must not be null");
    }
    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;
}
 
Example 7
Project: Tenable.io-SDK-for-Java   File: LoggerHelper.java   View Source Code Vote up 5 votes
public static LogLevel getLogLevel( Logger logger ) {
    if( logger.isTraceEnabled() )
        return LogLevel.TRACE;
    else if( logger.isDebugEnabled() )
        return LogLevel.DEBUG;
    else if( logger.isInfoEnabled() )
        return LogLevel.INFO;
    else if( logger.isWarnEnabled() )
        return LogLevel.WARN;
    else if( logger.isErrorEnabled() )
        return LogLevel.ERROR;

    return LogLevel.NONE;
}
 
Example 8
Project: slf4j-lambda   File: LambdaLoggerUtils.java   View Source Code Vote up 5 votes
/**
 * check if log level is enabled in the underlying logger
 *
 * @param underlyingLogger real Slf4j Logger implementation
 * @param logLevel log level
 * @param marker marker
 * @return true if log level is enabled or false.
 */
public static boolean isLogLevelEnabled(Logger underlyingLogger, Level logLevel, Marker marker) {
    switch (logLevel) {
        case TRACE:
            if (marker == null) {
                return underlyingLogger.isTraceEnabled();
            }
            return underlyingLogger.isTraceEnabled(marker);
        case DEBUG:
            if (marker == null) {
                return underlyingLogger.isDebugEnabled();
            }
            return underlyingLogger.isDebugEnabled(marker);
        case INFO:
            if (marker == null) {
                return underlyingLogger.isInfoEnabled();
            }
            return underlyingLogger.isInfoEnabled(marker);
        case WARN:
            if (marker == null) {
                return underlyingLogger.isWarnEnabled();
            }
            return underlyingLogger.isWarnEnabled(marker);
        case ERROR:
            if (marker == null) {
                return underlyingLogger.isErrorEnabled();
            }
            return underlyingLogger.isErrorEnabled(marker);
        default:
            break;
    }
    return false;
}
 
Example 9
Project: incubator-ratis   File: JavaUtils.java   View Source Code Vote up 5 votes
/** Attempt to get a return value from the given supplier multiple times. */
static <RETURN, THROWABLE extends Throwable> RETURN attempt(
    CheckedSupplier<RETURN, THROWABLE> supplier,
    int numAttempts, long sleepMs, String name, Logger log)
    throws THROWABLE, InterruptedException {
  Objects.requireNonNull(supplier, "supplier == null");
  Preconditions.assertTrue(numAttempts > 0, () -> "numAttempts = " + numAttempts + " <= 0");
  Preconditions.assertTrue(sleepMs >= 0L, () -> "sleepMs = " + sleepMs + " < 0");

  for(int i = 1; i <= numAttempts; i++) {
    try {
      return supplier.get();
    } catch (Throwable t) {
      if (i == numAttempts) {
        throw t;
      }
      if (log != null && log.isWarnEnabled()) {
        log.warn("FAILED " + name + " attempt #" + i + "/" + numAttempts
            + ": " + t + ", sleep " + sleepMs + "ms and then retry.", t);
      }
    }

    if (sleepMs > 0) {
      Thread.sleep(sleepMs);
    }
  }
  throw new IllegalStateException("BUG: this line should be unreachable.");
}
 
Example 10
Project: ait-platform   File: AitLogger.java   View Source Code Vote up 5 votes
/**
 * warn
 * @param logger
 * @param message
 * @param params
 */

public static void warn(Logger logger, String message, Object... params) {
	
	if (logger.isWarnEnabled()) {
		logger.warn(message, params);
	}
}
 
Example 11
Project: mzzb-server   File: AutoRunConfig.java   View Source Code Vote up 5 votes
private void fetchAmazonDiscsData(int retry) {
    Logger logger = LoggerFactory.getLogger(AutoRunConfig.class);
    if (retry == 0) {
        if (logger.isWarnEnabled()) {
            logger.warn("fetching amazon discs data failed");
        }
    } else {
        if (logger.isInfoEnabled()) {
            logger.info("fetching amazon discs data ({})", retry);
        }
        try {
            amazonDiscsSpider.fetch();
        } catch (IOException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("fetching amazon discs data throw an error", e);
            }
            if (retry > 0) {
                fetchSakuraSpeedData(retry - 1);
            } else {
                return;
            }
        }
        if (logger.isInfoEnabled()) {
            logger.info("fetched amazon discs data ({})", retry);
        }
    }
}
 
Example 12
Project: happylifeplat-transaction   File: LogUtil.java   View Source Code Vote up 4 votes
public static void warn(Logger logger,String format,Supplier<Object> supplier){
    if(logger.isWarnEnabled()){
        logger.warn(format,supplier.get());
    }
}
 
Example 13
Project: happylifeplat-transaction   File: LogUtil.java   View Source Code Vote up 4 votes
public static void warn(Logger logger,Supplier<Object> supplier){
    if(logger.isWarnEnabled()){
        logger.warn(Objects.toString(supplier.get()));
    }
}
 
Example 14
Project: OftenPorter   File: PortExecutor.java   View Source Code Vote up 4 votes
public void doRequest(PreRequest req, WRequest request, WResponse response, boolean isInnerRequest)
{
    WObjectImpl wObject = null;
    try
    {

        PorterOfFun funPort = req.funPort;
        Porter classPort = req.classPort;

        Context context = req.context;
        InnerContextBridge innerContextBridge = context.innerContextBridge;
        UrlDecoder.Result result = req.result;


        if (!isInnerRequest && funPort.getMethodPortIn()
                .getPortFunType() == PortFunType.INNER)
        {
            exNotFoundClassPort(request, response, innerContextBridge.responseWhenException);
            return;
        }


        wObject = new WObjectImpl(pName, result, request, response, context, isInnerRequest);
        IAttributeFactory attributeFactory = iAttributeFactory;
        Object originRequest = request.getOriginalRequest();
        if (originRequest != null && originRequest instanceof IAttributeFactory)
        {
            attributeFactory = (IAttributeFactory) originRequest;
        }
        wObject.setIAttribute(attributeFactory);

        if (funPort.getMethodPortIn().getTiedType().isRest())
        {
            wObject.restValue = result.funTied();
        }

        ParamSource paramSource = getParamSource(wObject, classPort, funPort);
        wObject.setParamSource(paramSource);
        //全局通过检测
        dealtOfGlobalCheck(context, funPort, wObject, innerContextBridge, result);
    } catch (Exception e)
    {
        Throwable ex = getCause(e);
        response.toErr();
        Logger LOGGER = logger(null);
        if (LOGGER.isWarnEnabled())
        {
            LOGGER.warn(ex.getMessage(), ex);
        }
        if (responseWhenException)
        {
            JResponse jResponse = new JResponse(ResultCode.EXCEPTION);
            jResponse.setDescription(WPTool.getMessage(ex));
            try
            {
                response.write(jResponse);
            } catch (IOException e1)
            {
                LOGGER.warn(e1.getMessage(), e1);
            }
        }
        close(response);

    } finally
    {
        if (wObject != null)
        {
            wObject.invokeAfterInvokeListeners();
        }
    }
}
 
Example 15
Project: centraldogma   File: Polyfills.java   View Source Code Vote up 4 votes
public static void consoleWarn(Logger logger, ScriptObjectMirror args) {
    if (logger.isWarnEnabled()) {
        logger.warn(logMessage(args));
    }
}
 
Example 16
Project: happylifeplat-tcc   File: LogUtil.java   View Source Code Vote up 4 votes
public static void warn(Logger logger, String format, Supplier<Object> supplier) {
    if (logger.isWarnEnabled()) {
        logger.warn(format, supplier.get());
    }
}
 
Example 17
Project: happylifeplat-tcc   File: LogUtil.java   View Source Code Vote up 4 votes
public static void warn(Logger logger, Supplier<Object> supplier) {
    if (logger.isWarnEnabled()) {
        logger.warn(Objects.toString(supplier.get()));
    }
}
 
Example 18
Project: myth   File: LogUtil.java   View Source Code Vote up 4 votes
public static void warn(Logger logger, String format, Supplier<Object> supplier) {
    if (logger.isWarnEnabled()) {
        logger.warn(format, supplier.get());
    }
}
 
Example 19
Project: myth   File: LogUtil.java   View Source Code Vote up 4 votes
public static void warn(Logger logger, Supplier<Object> supplier) {
    if (logger.isWarnEnabled()) {
        logger.warn(Objects.toString(supplier.get()));
    }
}
 
Example 20
Project: asura   File: LogUtil.java   View Source Code Vote up 2 votes
/**
 * warn level
 * @param logger
 * @param s
 * @param objs
 */
public static void warn(Logger logger,String s,Object... objs){
    if(logger.isWarnEnabled()){
        logger.warn(s, objs);
    }
}