Java Code Examples for org.slf4j.Logger#isInfoEnabled()

The following examples show how to use org.slf4j.Logger#isInfoEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Slf4jSessionLogger.java    From testgrid with Apache License 2.0 6 votes vote down vote up
@Override
public boolean shouldLog(int level, String category) {
   Logger logger = getLogger(category);
   LogLevel logLevel = getLogLevel(level);
   switch (logLevel) {
   case TRACE:
      return logger.isTraceEnabled();
   case DEBUG:
      return logger.isDebugEnabled();
   case INFO:
      return logger.isInfoEnabled();
   case WARN:
      return logger.isWarnEnabled();
   case ERROR:
      return logger.isErrorEnabled();
   default:
      return true;
   }
}
 
Example 2
Source File: OAuthHelper.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the string representation of the request  to use for the redirect (the URL
 * to return to after oauth login completes). The returned URL will include the host and
 * path, but no query parameters. If this server has not been configured with a different
 * authentication host, then the server that received this request is considered to
 * be the authentication server.
 */
static StringBuffer getAuthServerRequest(HttpServletRequest req) {
	//use authentication host for redirect because we may be sitting behind a proxy
	String hostPref = PreferenceHelper.getString(ServerConstants.CONFIG_AUTH_HOST, null);
	//assume non-proxy direct server connection if no auth host defined
	if (hostPref == null)
		return req.getRequestURL();
	StringBuffer result = new StringBuffer(hostPref);
	result.append(req.getServletPath());
	if (req.getPathInfo() != null)
		result.append(req.getPathInfo());

	Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.oauth"); //$NON-NLS-1$
	if (logger.isInfoEnabled())
		logger.info("Auth server redirect: " + result.toString()); //$NON-NLS-1$
	return result;
}
 
Example 3
Source File: StatementConfiguration.java    From enmasse with Apache License 2.0 6 votes vote down vote up
public void dump(final Logger logger) {

        if (!logger.isInfoEnabled()) {
            return;
        }

        logger.info("Dumping statement configuration");
        logger.info("Format arguments: {}", this.formatArguments);

        final String[] keys = this.statements.keySet().toArray(String[]::new);
        Arrays.sort(keys);
        logger.info("Statements:");
        for (String key : keys) {
            logger.info("{}\n{}", key, this.statements.get(key));
        }

    }
 
Example 4
Source File: ReflectionUtils.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Log the current thread stacks at INFO level.
 * @param log the logger that logs the stack trace
 * @param title a descriptive title for the call stacks
 * @param minInterval the minimum time from the last
 */
public static void logThreadInfo(Logger log,
                                 String title,
                                 long minInterval) {
  boolean dumpStack = false;
  if (log.isInfoEnabled()) {
    synchronized (ReflectionUtils.class) {
      long now = System.currentTimeMillis();
      if (now - previousLogTime >= minInterval * 1000) {
        previousLogTime = now;
        dumpStack = true;
      }
    }
    if (dumpStack) {
      try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title);
        log.info(buffer.toString(Charset.defaultCharset().name()));
      } catch (UnsupportedEncodingException ignored) {
        log.warn("Could not write thread info about '" + title +
            "' due to a string encoding issue.");
      }
    }
  }
}
 
Example 5
Source File: Slf4jSessionLogger.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean shouldLog(int level, String category){
	Logger logger = getLogger(category);
	LogLevel logLevel = getLogLevel(level);
	
	switch (logLevel) {
	case TRACE:
		return logger.isTraceEnabled();
	case DEBUG:
		return logger.isDebugEnabled();
	case INFO:
		return logger.isInfoEnabled();
	case WARN:
		return logger.isWarnEnabled();
	case ERROR:
		return logger.isErrorEnabled();
	default:
		return true;
	}
}
 
Example 6
Source File: StatementConfiguration.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Dump the configuration to a logger.
 *
 * @param logger The logger to dump to.
 */
public void dump(final Logger logger) {

    if (!logger.isInfoEnabled()) {
        return;
    }

    logger.info("Dumping statement configuration");
    logger.info("Format arguments: {}", this.formatArguments);

    final String[] keys = this.statements.keySet().toArray(String[]::new);
    Arrays.sort(keys);
    logger.info("Statements:");
    for (String key : keys) {
        logger.info("{}\n{}", key, this.statements.get(key));
    }

}
 
Example 7
Source File: VariableLevelLog.java    From data-prep with Apache License 2.0 6 votes vote down vote up
/**
 * Check whether a SLF4J logger is enabled for a certain loglevel.
 * If the "logger" or the "level" is null, false is returned.
 */
public static boolean isEnabledFor(Logger logger, Level level) {
    boolean res = false;
    if (logger != null && level != null) {
        switch (level) {
        case TRACE:
            res = logger.isTraceEnabled();
            break;
        case DEBUG:
            res = logger.isDebugEnabled();
            break;
        case INFO:
            res = logger.isInfoEnabled();
            break;
        case WARN:
            res = logger.isWarnEnabled();
            break;
        case ERROR:
            res = logger.isErrorEnabled();
            break;
        }
    }
    return res;
}
 
Example 8
Source File: LambdaLoggerUtils.java    From slf4j-lambda with Apache License 2.0 5 votes vote down vote up
/**
 * 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
Source File: LogUtils.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
static void infoOrTrace(Logger log, Supplier<String> message, Throwable t) {
  if (log.isTraceEnabled()) {
    log.trace(message.get(), t);
  } else if (log.isInfoEnabled()) {
    log.info("{}: {}", message.get(), String.valueOf(t));
  }
}
 
Example 10
Source File: HashCaptchaChecker.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public CaptchaSignedResult encode(String code){
	long validTime = getValidTime();
	Logger logger = JFishLoggerFactory.getCommonLogger();
	if(logger.isInfoEnabled()){
		logger.info("signing validTime: {}", validTime);
	}
	String source = code.toUpperCase()+salt+validTime;
	String signed = hasher.hash(source);
	return new CaptchaSignedResult(signed, validTime);
}
 
Example 11
Source File: LoggerProxy.java    From x7 with Apache License 2.0 5 votes vote down vote up
public static void info(Class clzz, Object obj) {
    Logger logger = loggerMap.get(clzz);
    if (logger == null || obj == null)
        return;
    else if (logger.isInfoEnabled()){
        logger.info(obj.toString());
    }
}
 
Example 12
Source File: Slf4jSessionLogger.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean shouldLog(final int level, final String category) {
    Logger logger = getLogger(category);
    boolean resp = false;

    LogLevel logLevel = getLogLevel(level);

    switch (logLevel) {
    case TRACE:
        resp = logger.isTraceEnabled();
        break;
    case DEBUG:
        resp = logger.isDebugEnabled();
        break;
    case INFO:
        resp = logger.isInfoEnabled();
        break;
    case WARN:
        resp = logger.isWarnEnabled();
        break;
    case ERROR:
        resp = logger.isErrorEnabled();
        break;
    default:
        throw new IllegalStateException("Not supported" + logLevel);
    }

    return resp;
}
 
Example 13
Source File: AuditLogUtil.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void infoWrapper( Logger log, String username, Object object, String action )
{
    if ( log.isInfoEnabled() )
    {
        if ( username != null && object instanceof IdentifiableObject )
        {
            IdentifiableObject idObject = (IdentifiableObject) object;
            StringBuilder builder = new StringBuilder();

            builder.append( "'" ).append( username ).append( "' " ).append( action );

            if ( !ProxyFactory.isProxyClass( object.getClass() ) )
            {
                builder.append( " " ).append( object.getClass().getName() );
            }
            else
            {
                builder.append( " " ).append( object.getClass().getSuperclass().getName() );
            }

            if ( idObject.getName() != null && !idObject.getName().isEmpty() )
            {
                builder.append( ", name: " ).append( idObject.getName() );
            }

            if ( idObject.getUid() != null && !idObject.getUid().isEmpty() )
            {
                builder.append( ", uid: " ).append( idObject.getUid() );
            }

            log.info( builder.toString() );
        }
    }
}
 
Example 14
Source File: SimpleDatabaseTransactionMessageInterceptor.java    From onetwo with Apache License 2.0 5 votes vote down vote up
protected void sendMessage(SendMessageContext<?> msgContext){
		msgContext.getChain().invoke();
//		sendMessageRepository.remove(Arrays.asList(event.getSendMessageContext()));
		getSendMessageRepository().updateToSent(msgContext);
		Logger log = getLogger();
		if(msgContext.isDebug() && log.isInfoEnabled()){
			log.info("committed transactional message in thread[{}]...", Thread.currentThread().getId());
		}
	}
 
Example 15
Source File: MemoryLogger.java    From flink with Apache License 2.0 5 votes vote down vote up
public static void startIfConfigured(
		Logger logger,
		Configuration configuration,
		CompletableFuture<Void> taskManagerTerminationFuture) {
	if (!logger.isInfoEnabled() || !configuration.getBoolean(TaskManagerOptions.DEBUG_MEMORY_LOG)) {
		return;
	}
	logger.info("Starting periodic memory usage logger");

	new MemoryLogger(
		logger,
		configuration.getLong(TaskManagerOptions.DEBUG_MEMORY_USAGE_LOG_INTERVAL_MS),
		taskManagerTerminationFuture).start();
}
 
Example 16
Source File: LogUtil.java    From hmily with Apache License 2.0 2 votes vote down vote up
/**
 * Info.
 *
 * @param logger   the logger
 * @param supplier the supplier
 */
public static void info(Logger logger, Supplier<Object> supplier) {
    if (logger.isInfoEnabled()) {
        logger.info(Objects.toString(supplier.get()));
    }
}
 
Example 17
Source File: LogUtils.java    From soul with Apache License 2.0 2 votes vote down vote up
/**
 * info log.
 *
 * @param logger   logger
 * @param supplier {@linkplain Supplier}
 */
public static void info(final Logger logger, final Supplier<Object> supplier) {
    if (logger.isInfoEnabled()) {
        logger.info(Objects.toString(supplier.get()));
    }
}
 
Example 18
Source File: LogUtil.java    From myth with Apache License 2.0 2 votes vote down vote up
/**
 * Info.
 *
 * @param logger   the logger
 * @param supplier the supplier
 */
public static void info(Logger logger, Supplier<Object> supplier) {
    if (logger.isInfoEnabled()) {
        logger.info(Objects.toString(supplier.get()));
    }
}
 
Example 19
Source File: LogUtil.java    From myth with Apache License 2.0 2 votes vote down vote up
/**
 * Info.
 *
 * @param logger   the logger
 * @param format   the format
 * @param supplier the supplier
 */
public static void info(Logger logger, String format, Supplier<Object> supplier) {
    if (logger.isInfoEnabled()) {
        logger.info(format, supplier.get());
    }
}
 
Example 20
Source File: LogUtil.java    From hmily with Apache License 2.0 2 votes vote down vote up
/**
 * Info.
 *
 * @param logger   the logger
 * @param format   the format
 * @param supplier the supplier
 */
public static void info(Logger logger, String format, Supplier<Object> supplier) {
    if (logger.isInfoEnabled()) {
        logger.info(format, supplier.get());
    }
}