Record Class Logging<T>
java.lang.Object
java.lang.Record
com.winterhavenmc.library.messagebuilder.models.validation.Logging<T>
- Type Parameters:
T- the type of the value being validated
- All Implemented Interfaces:
Validator<T>
public record Logging<T>(LogLevel logLevel, ErrorMessageKey messageKey, Parameter parameter)
extends Record
implements Validator<T>
A
Validator implementation that logs a warning or error
when a value fails validation, but does not throw.
This handler is useful in cases where validation failures are non-critical or should be tracked without disrupting normal flow.
The message is localized using Validator.formatMessage(ErrorMessageKey, Parameter),
and is logged using the Java Logger API.
The LogLevel enum provides a clearer abstraction over
Level for improved readability and intent.
Typical usage:
import com.winterhavenmc.library.messagebuilder.models.validation.Validator;validate(value, Predicate, Validator.logging(logLevel, ErrorMessageKey, Parameter));
- See Also:
-
Field Summary
Fields inherited from interface com.winterhavenmc.library.messagebuilder.models.validation.Validator
BUNDLE_NAME -
Constructor Summary
ConstructorsConstructorDescriptionLogging(LogLevel logLevel, ErrorMessageKey messageKey, Parameter parameter) Creates an instance of aLoggingrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.handleInvalid(T value) Logs a validation failure using the specified log level and message, but continues execution by returning the original value.final inthashCode()Returns a hash code value for this object.logLevel()Returns the value of thelogLevelrecord component.Returns the value of themessageKeyrecord component.Returns the value of theparameterrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Logging
Creates an instance of aLoggingrecord class.- Parameters:
logLevel- the value for thelogLevelrecord componentmessageKey- the value for themessageKeyrecord componentparameter- the value for theparameterrecord component
-
-
Method Details
-
handleInvalid
Logs a validation failure using the specified log level and message, but continues execution by returning the original value.- Specified by:
handleInvalidin interfaceValidator<T>- Parameters:
value- the invalid value- Returns:
- an
Optionalcontaining the value, despite being invalid
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
logLevel
Returns the value of thelogLevelrecord component.- Returns:
- the value of the
logLevelrecord component
-
messageKey
Returns the value of themessageKeyrecord component.- Returns:
- the value of the
messageKeyrecord component
-
parameter
Returns the value of theparameterrecord component.- Returns:
- the value of the
parameterrecord component
-