Java Code Examples for org.springframework.boot.logging.LogLevel#ordinal()

The following examples show how to use org.springframework.boot.logging.LogLevel#ordinal() . 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: LogValidator.java    From eclair with Apache License 2.0 6 votes vote down vote up
@Override
public void validate(Method method, T target) throws AnnotationUsageException {
    LogLevel expectedLevel = AnnotationAttribute.LEVEL.extract(target);
    LogLevel ifEnabledLevel = AnnotationAttribute.IF_ENABLED.extract(target);
    if (ifEnabledLevel.ordinal() >= expectedLevel.ordinal() && ifEnabledLevel != OFF) {
        throw new AnnotationUsageException(method,
                format("'ifEnabled = %s' should be more strict than 'level = %s'", ifEnabledLevel, expectedLevel),
                "Correct specified levels relation or replace 'ifEnabled' by default value 'OFF'",
                target);
    }

    String printerName = AnnotationAttribute.PRINTER.extract(target);
    if (StringUtils.hasText(printerName)) {
        Printer printer = printerResolver.resolve(printerName);
        if (isNull(printer)) {
            throw new AnnotationUsageException(method,
                    format("Unknown printer '%s'", printerName),
                    "Use correct bean name or alias to specify 'printer'",
                    target);
        }
    }
}
 
Example 2
Source File: SimpleLogger.java    From eclair with Apache License 2.0 4 votes vote down vote up
/**
 * Performs the logging of 'in'-event (beginning of method execution).
 *
 * @param invocation current loggable method invocation
 * @param methodLog  definition of invoked method logging
 */
@Override
protected void logIn(MethodInvocation invocation, MethodLog methodLog) {
    String loggerName = getLoggerName(invocation);
    LogLevel level = null;

    // initialize 'inLog' attributes
    InLog inLog = methodLog.getInLog();
    boolean isInLogLogEnabled = false;
    boolean isInLogVerboseLogEnabled = false;
    if (nonNull(inLog)) {
        LogLevel inLogLevel = inLog.getLevel();
        isInLogLogEnabled = (inLogLevel != OFF) && isLogEnabled(loggerName, expectedLevelResolver.apply(inLog));
        if (isInLogLogEnabled) {
            level = inLogLevel;
            isInLogVerboseLogEnabled = isLogEnabled(loggerName, inLog.getVerboseLevel());
        }
    }

    StringBuilder builder = new StringBuilder();
    boolean isParameterLogVerboseFound = false;
    boolean isParameterLogSkippedFound = false;
    Object[] arguments = invocation.getArguments();
    for (int a = 0; a < arguments.length; a++) {
        ParameterLog parameterLog = methodLog.getParameterLogs().get(a);
        boolean isParameterLogDefined = nonNull(parameterLog);

        // filter argument
        if (isParameterLogDefined) {
            LogLevel parameterLogLevel = parameterLog.getLevel();
            if (parameterLogLevel == OFF || !isLogEnabled(loggerName, expectedLevelResolver.apply(parameterLog))) {
                isParameterLogSkippedFound = true;
                continue;
            }
            if (!isInLogLogEnabled) {
                if (isNull(level) || parameterLogLevel.ordinal() > level.ordinal()) {
                    level = parameterLogLevel;
                }
            }
        } else if (!isInLogVerboseLogEnabled) {
            isParameterLogSkippedFound = true;
            continue;
        }

        // print delimiter
        if (isParameterLogVerboseFound) {
            builder.append(", ");
        } else {
            builder.append(" ");
            isParameterLogVerboseFound = true;
        }

        // print parameter name
        if (!isParameterLogDefined || isLogEnabled(loggerName, parameterLog.getVerboseLevel())) {
            String parameterName = methodLog.getParameterNames().get(a);
            if (nonNull(parameterName)) {
                builder.append(parameterName).append("=");
            } else if (isParameterLogSkippedFound) {
                builder.append(Integer.toString(a)).append("=");
            }
        }

        // print parameter value
        Object argument = arguments[a];
        if (isNull(argument)) {
            builder.append((String) null);
        } else if (isParameterLogDefined) {
            builder.append(printArgument(parameterLog.getPrinter(), argument));
        } else {
            builder.append(printArgument(inLog.getPrinters().get(a), argument));
        }
    }

    if (isInLogLogEnabled || isParameterLogVerboseFound) {
        String message = IN + builder.toString();
        loggerFacadeFactory.getLoggerFacade(loggerName).log(level, message);
    }
}
 
Example 3
Source File: ExpectedLevelResolver.java    From eclair with Apache License 2.0 4 votes vote down vote up
private LogLevel min(LogLevel level1, LogLevel level2) {
    return level1.ordinal() <= level2.ordinal() ? level1 : level2;
}
 
Example 4
Source File: SimpleLogger.java    From eclair with Apache License 2.0 2 votes vote down vote up
/**
 * Determines if log level is enabled for logger specified by name.
 *
 * @param loggerName checkable logger name
 * @param level      checkable level
 * @return {@code true} if enabled, {@code false} otherwise
 */
@Override
protected boolean isLogEnabled(String loggerName, LogLevel level) {
    return level != OFF &&
            level.ordinal() >= loggingSystem.getLoggerConfiguration(loggerName).getEffectiveLevel().ordinal();
}