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

The following examples show how to use org.slf4j.Logger#isDebugEnabled() . 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: LoggingAspect.java    From jhipster-registry with Apache License 2.0 6 votes vote down vote up
/**
 * Advice that logs when a method is entered and exited.
 *
 * @param joinPoint join point for advice.
 * @return result.
 * @throws Throwable throws {@link IllegalArgumentException}.
 */
@Around("applicationPackagePointcut() && springBeanPointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    Logger log = logger(joinPoint);
    if (log.isDebugEnabled()) {
        log.debug("Enter: {}() with argument[s] = {}", joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
    }
    try {
        Object result = joinPoint.proceed();
        if (log.isDebugEnabled()) {
            log.debug("Exit: {}() with result = {}", joinPoint.getSignature().getName(), result);
        }
        return result;
    } catch (IllegalArgumentException e) {
        log.error("Illegal argument: {} in {}()", Arrays.toString(joinPoint.getArgs()), joinPoint.getSignature().getName());
        throw e;
    }
}
 
Example 2
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 3
Source File: DataSource.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
static void debug(Logger logger, String sql, @Nullable Object... args) {
    if (!logger.isDebugEnabled()) {
        return;
    }
    if (args.length == 0) {
        logger.debug(sql);
        return;
    }
    List<String> argStrings = Lists.newArrayList();
    for (Object arg : args) {
        if (arg instanceof String) {
            argStrings.add('\'' + (String) arg + '\'');
        } else if (arg == null) {
            argStrings.add("NULL");
        } else {
            argStrings.add(checkNotNull(arg.toString()));
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{} [{}]", sql, Joiner.on(", ").join(argStrings));
    }
}
 
Example 4
Source File: RecognizerErrorHandler.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Format an error message as expected by ANTLR. It is basically the
 * same error message that ANTL BaseRecognizer generates with some
 * additional data.
 * Also used to log debugging information.
 * @param log the logger to use at debug time
 * @param recognizer the lexer or parser who generated the error
 * @param e the exception that occured
 * @param superMessage the error message that the super class generated
 * @param tokenNames list of token names
 * @return a formatted error message
 */
public static String getErrorMessage(
        final Logger log,
        final BaseRecognizer recognizer,
        final RecognitionException e,
        final String superMessage,
        final String[] tokenNames) {
    if (log.isDebugEnabled()) {
        List < ? > stack = BaseRecognizer.getRuleInvocationStack(
                e, recognizer.getClass().getSuperclass().getName());
        String debugMsg = recognizer.getErrorHeader(e)
            + " " + e.getClass().getSimpleName()
            + ": " + superMessage
            + ":";
        if (e instanceof NoViableAltException) {
            NoViableAltException nvae = (NoViableAltException) e;
            debugMsg += " (decision=" + nvae.decisionNumber
            + " state=" + nvae.stateNumber + ")"
            + " decision=<<" + nvae.grammarDecisionDescription + ">>";
        } else if (e instanceof UnwantedTokenException) {
            UnwantedTokenException ute = (UnwantedTokenException) e;
            debugMsg += " (unexpected token=" + toString(ute.getUnexpectedToken(), tokenNames) + ")";

        } else if (e instanceof EarlyExitException) {
            EarlyExitException eea = (EarlyExitException) e;
            debugMsg += " (decision=" + eea.decisionNumber + ")";
        }
        debugMsg += " ruleStack=" + stack.toString();
        log.debug(debugMsg);
    }

    return makeUserMsg(e, superMessage);
}
 
Example 5
Source File: LoggingResourceFilter.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private boolean isLogEnabled(Logger logger, LogLevel level) {
    switch (level) {
    case TRACE: return logger.isTraceEnabled();
    case DEBUG: return logger.isDebugEnabled();
    case INFO: return logger.isInfoEnabled();
    default: throw new IllegalStateException("Unexpected log level: "+level);
    }
}
 
Example 6
Source File: LoggingAspect.java    From spring-cache-self-refresh with MIT License 5 votes vote down vote up
/**
 * Logs the entry to and exit from any method under the configured package.
 * 
 * @param joinPoint
 * @return
 */
public Object logAround(final ProceedingJoinPoint joinPoint) throws Throwable { // NOSONAR
	// No sonar comment is to skip sonar Throwable violation, which can not
	// be avoided
	Object ret = joinPoint.proceed();
	final Logger targetLogger = LoggingAspect.getLogger(joinPoint.getSourceLocation().getWithinType());
	if (targetLogger.isDebugEnabled()) {
		targetLogger.debug(LoggingAspect.METHOD_ARGS_RETURN, new String[] { joinPoint.getSignature().getName(),
				Arrays.toString(joinPoint.getArgs()), ret != null ? ret.toString() : null });
	}
	return ret;

}
 
Example 7
Source File: Journal.java    From cosmic with Apache License 2.0 5 votes vote down vote up
public void record(final Logger logger, final String msg, final Object... params) {
    if (logger.isDebugEnabled()) {
        final StringBuilder buf = new StringBuilder();
        toString(buf, msg, params);
        final String entry = buf.toString();
        log(entry);
        logger.debug(entry);
    } else {
        log(msg, params);
    }
}
 
Example 8
Source File: LogUtils.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
public static Consumer<Object> ifDebugEnabled(
    Logger log, Supplier<String> message) {

    return o -> {
        if (log.isDebugEnabled()) {
            log.debug(message.get(), o);
        }
    };
}
 
Example 9
Source File: LoggerProxy.java    From x7 with Apache License 2.0 5 votes vote down vote up
public static void debug(Class clzz,  LogCallable callable) {
    Logger logger = loggerMap.get(clzz);
    if (logger == null )
        return;
    if (logger.isDebugEnabled()) {
        if (callable == null)
            return;
        String str = callable.call();
        if (StringUtil.isNullOrEmpty(str))
            return;
        logger.debug(str);
    }
}
 
Example 10
Source File: RxIris.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private static <T> void dolog(final LogLevel level, final Logger log, final String format, Object... value) {
   switch (level) {
   case TRACE:
      if (log.isTraceEnabled())
         log.trace(format, value);
      break;

   case DEBUG:
      if (log.isDebugEnabled())
         log.debug(format, value);
      break;

   case INFO:
      if (log.isInfoEnabled())
         log.info(format, value);
      break;

   case WARN:
      if (log.isWarnEnabled())
         log.warn(format, value);
      break;

   case ERROR:
      if (log.isErrorEnabled())
         log.error(format, value);
      break;

   default:
      break;
   }
}
 
Example 11
Source File: ServerRequest.java    From rockscript with Apache License 2.0 5 votes vote down vote up
@Override
public void logBodyString(String bodyString, Logger log) {
  if (log.isDebugEnabled()) {
    if (bodyString!=null) {
      BufferedReader reader = new BufferedReader(new StringReader(bodyString));
      reader.lines().forEach(line->log.debug("  "+line));
    } else {
      log.debug("  ---body-is-null---");
    }
  }
}
 
Example 12
Source File: DataHelper.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
public static void aggregateProcessData(ProcessDataSet data, Logger logger) {
    long start = System.nanoTime();
    Map<String, List<Process>> processNameToProcesses = DataHelper.getProcessesByName(data, false);

    for (List<Process> processes : processNameToProcesses.values()) {
        if (processes.size() > 1) {
            aggregateProcesses(data, processes, logger);
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Aggregated process data for {} in {}ms ", data, (System.nanoTime() - start) / 1000000.0d);
    }
}
 
Example 13
Source File: PrelTransformer.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static void log(final SqlHandlerConfig config, final String name, final PhysicalPlan plan, final Logger logger) throws JsonProcessingException {
  if (logger.isDebugEnabled()) {
    String planText = plan.unparse(config.getContext().getLpPersistence().getMapper().writer());
    logger.debug(name + " : \n" + planText);
  }
}
 
Example 14
Source File: SFTPLogger.java    From sftp-fs with Apache License 2.0 4 votes vote down vote up
public static void createdInputStream(Logger logger, String channelId, String path) {
    if (logger != null && logger.isDebugEnabled()) {
        logger.debug(String.format(getMessage("log.createdInputStream"), channelId, path)); //$NON-NLS-1$
    }
}
 
Example 15
Source File: SFTPLogger.java    From sftp-fs with Apache License 2.0 4 votes vote down vote up
public static void closedOutputStream(Logger logger, String channelId, String path) {
    if (logger != null && logger.isDebugEnabled()) {
        logger.debug(String.format(getMessage("log.closedOutputStream"), channelId, path)); //$NON-NLS-1$
    }
}
 
Example 16
Source File: SimpleSemaphore.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
/**
 * Grants a lock on the identified resource to the calling thread (blocking
 * until it is available).
 * 
 * @return true if the lock was obtained.
 */
public synchronized boolean obtainLock(Connection conn, String lockName) {

    lockName = lockName.intern();

    Logger log = getLog();

    if(log.isDebugEnabled()) {
        log.debug(
            "Lock '" + lockName + "' is desired by: "
                    + Thread.currentThread().getName());
    }

    if (!isLockOwner(conn, lockName)) {
        if(log.isDebugEnabled()) {
            log.debug(
                "Lock '" + lockName + "' is being obtained: "
                        + Thread.currentThread().getName());
        }
        while (locks.contains(lockName)) {
            try {
                this.wait();
            } catch (InterruptedException ie) {
                if(log.isDebugEnabled()) {
                    log.debug(
                        "Lock '" + lockName + "' was not obtained by: "
                                + Thread.currentThread().getName());
                }
            }
        }

        if(log.isDebugEnabled()) {
            log.debug(
                "Lock '" + lockName + "' given to: "
                        + Thread.currentThread().getName());
        }
        getThreadLocks().add(lockName);
        locks.add(lockName);
    } else if(log.isDebugEnabled()) {
        log.debug(
            "Lock '" + lockName + "' already owned by: "
                    + Thread.currentThread().getName()
                    + " -- but not owner!",
            new Exception("stack-trace of wrongful returner"));
    }

    return true;
}
 
Example 17
Source File: RequestLogger.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private static boolean isLevelEnabled(Level logLevel, Logger logger) {
  return (logLevel == Level.INFO && logger.isInfoEnabled())
      || (logLevel == Level.WARN && logger.isWarnEnabled())
      || (logLevel == Level.DEBUG && logger.isDebugEnabled());
}
 
Example 18
Source File: SFTPLogger.java    From sftp-fs with Apache License 2.0 4 votes vote down vote up
public static void failedToCreatePool(Logger logger, IOException e) {
    if (logger != null && logger.isDebugEnabled()) {
        logger.debug(getMessage("log.failedToCreatePool"), e); //$NON-NLS-1$
    }
}
 
Example 19
Source File: LogUtils.java    From tankbattle with MIT License 4 votes vote down vote up
public static void debug(String message) {
    Logger log = getLogger(getClassName());
    if (log.isDebugEnabled()) {
        log.debug(message);
    }
}
 
Example 20
Source File: ScopeHelper.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * This is a just a helper method to determine whether request scope
 * creation/deletion issues should be logged or not.
 *
 * @param aLogger
 *        The logger to check.
 * @return <code>true</code> if request scope creation/deletion should be
 *         logged, <code>false</code> otherwise.
 */
public static boolean debugRequestScopeLifeCycle (@Nonnull final Logger aLogger)
{
  // Also debug scopes, if debug logging is enabled
  if (aLogger.isDebugEnabled ())
    return true;

  return (isLifeCycleDebuggingEnabled () || isDebugRequestScopeEnabled ()) && aLogger.isInfoEnabled ();
}