@Pure @Override public int hashCode() { int hash = 7; hash = 83 * hash + threshold.hashCode(); hash = 83 * hash + Objects.hashCode(callerPrefix); hash = 83 * hash + Objects.hashCode(threadPrefix); hash = 83 * hash + Objects.hashCode(messageRegex); return hash; }
/** * Encodes this logging rule. */ @Pure public @Nonnull String encode() { final @Nonnull StringBuilder result = new StringBuilder(threshold.toString()); if (callerPrefix != null || threadPrefix != null || messageRegex != null) { result.append(";"); if (callerPrefix != null) { result.append(" ").append(callerPrefix); } if (threadPrefix != null || messageRegex != null) { result.append(";"); if (threadPrefix != null) { result.append(" ").append(threadPrefix); } if (messageRegex != null) { result.append("; ").append(messageRegex); } } } return result.toString(); }
@Pure @Override public @Nonnull String toString() { return Strings.uppercaseFirstCharacter(name().toLowerCase()); }
/** * Decodes the given line and returns the corresponding rule. * * @throws IllegalArgumentException if a rule has an invalid level. */ @Pure public static @Nonnull LoggingRule decode(@Nonnull String line) throws IllegalArgumentException { final @Nonnull @NonNullableElements String[] tokens = line.split(";", 4); final @Nonnull Level threshold = Level.valueOf(tokens[0].trim().toUpperCase()); final @Nullable String callerPrefix = getNonEmpty(tokens, 1); final @Nullable String threadPrefix = getNonEmpty(tokens, 2); final @Nullable String messageRegex = getNonEmpty(tokens, 3); return new LoggingRule(threshold, callerPrefix, threadPrefix, messageRegex); }
/** * Returns whether this rule accepts the given message with the given arguments. */ @Pure public boolean accepts(@Nonnull Level level, @Nonnull String caller, @Nonnull String thread, @Nonnull String message) { return level.getValue() >= threshold.getValue() && (callerPrefix == null || caller.startsWith(callerPrefix)) && (threadPrefix == null || thread.startsWith(threadPrefix)) && (messageRegex == null || message.matches(messageRegex)); }
/** * Logs the given message with the given position at the given level. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure protected static void log(@Nonnull Level level, @Nonnull CharSequence message, @Nullable SourcePosition position, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(level, message + (position != null ? " " + position : ""), null, arguments); if (level.getValue() >= Level.INFORMATION.getValue() && StaticProcessingEnvironment.environment.isSet()) { if (position == null) { StaticProcessingEnvironment.environment.get().getMessager().printMessage(levelToKind.get(level), Strings.format(message, arguments)); } else if (position.getAnnotationValue() != null) { StaticProcessingEnvironment.environment.get().getMessager().printMessage(levelToKind.get(level), Strings.format(message, arguments), position.getElement(), position.getAnnotationMirror(), position.getAnnotationValue()); } else if (position.getAnnotationMirror() != null) { StaticProcessingEnvironment.environment.get().getMessager().printMessage(levelToKind.get(level), Strings.format(message, arguments), position.getElement(), position.getAnnotationMirror()); } else { StaticProcessingEnvironment.environment.get().getMessager().printMessage(levelToKind.get(level), Strings.format(message, arguments), position.getElement()); } } }